标题:ajax+java问题
取消只看楼主
晋加答
Rank: 1
来 自:广东-深圳
等 级:新手上路
帖 子:137
专家分:0
注 册:2008-4-1
 问题点数:0 回复次数:0 
ajax+java问题
ajax部分代码如下:
function proce() {
 if (XMLHttpReq.readyState == 4) {
  if (XMLHttpReq.status == 200) {
   //var root = XMLHttpReq.responseXML;
   var xml = XMLHttpReq.responseXML;
      var root = xml.documentElement;
   
   var res = root.getElementsByTagName("content")[0].firstChild.data;
   var test = root.getElementsByTagName("test")[0].firstChild.data;
   if(res=="success")
     {window.location.href("success.jsp");}
   else
     {window.alert(res);window.location.href("regist.jsp");}

   
  } else {
   window.alert("exception");
  }
 }
}



问题是:
res=success时,怎么还是进入到
  {window.alert(res);window.location.href("regist.jsp");}这个里面来呢???
LoginAction代码如下:
public class LoginAction extends Action
{
   public ActionForward execute(ActionMapping mapping, ActionForm actionform, HttpServletRequest request, HttpServletResponse response)
  {
       String name = request.getParameter("name");
       String ps = request.getParameter("ps");
       DB db=new DB();
      
  try {
       request.setCharacterEncoding("gb2312");
      }
  catch (UnsupportedEncodingException e)
      {  e.printStackTrace(); }
  try
    {
       String msgStr="";
       response.setContentType("text/xml;charset=GB2312");
       response.setHeader("Cache-Control","no-cache");

       System.out.println("name = "+name+"  ps ="+ps);
       db.getCon();
       db.getStmt();
       boolean hasname=db.ifhas(name);
       boolean match= db.Match(name, ps);
      
       if(!hasname)
       { msgStr ="无此用户!"; }
       else if(!match)
       { msgStr ="密码错误!"; }
       else
       {
           msgStr ="success";
           
          //return (mapping.findForward("success"));
       }
           System.out.println("msgStr = "+msgStr);
           response.getWriter().println("<?xml version='1.0' encoding='GB2312' ?>");
           response.getWriter().println("<root>");
           response.getWriter().println("<content>");
           response.getWriter().print(msgStr);
           response.getWriter().println("</content>");
           response.getWriter().println("<test>");
           response.getWriter().println("正在测试。。。");
           response.getWriter().println("</test>");
           response.getWriter().println("</root>");
           response.getWriter().close();
           
           db.close();
           System.out.println("关闭连接!");
           return null;
           
    }
  catch(Exception ex)
     { ex.printStackTrace();
       db.close();
       System.out.println("异常,关闭连接!");
       return null;
     }  

  }
}
搜索更多相关主题的帖子: function content test 
2010-12-30 10:45



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-330269-1-1.html




关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.139613 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved