注册 登录
编程论坛 jQuery论坛

ajax+java问题

晋加答 发布于 2010-12-30 10:45, 4709 次点击
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;
     }  

  }
}
1 回复
#2
zdl20502010-12-30 16:04
你俩个return 返回的都是null,前台当然就得到的是null,判断始终就是false
1