日期:2014-05-20  浏览次数:20803 次

ajax dwr如何存储request对象
JScript code
    function ajaxcheck()
        {
            alert("ajax");
            var obj = document.form1;
            var name=obj.username.value.trim();//trim()功能删除字符串首部和尾部的空格
            var pwd=obj.password.value.trim();
            alert(name);
            ajaxcommon.doCheck(name,pwd,reloadym);
        }
    function reloadym(msg)
        {
            if(msg){
                alert("欢迎登录");
            }else{
                alert("用户名或密码错误");
            }
            //document.location.reload(true);
            window.location.href="welcome.jsp";
        }

Java code

    public boolean doCheck(String name,String password){
        WebContext webContext = WebContextFactory.get();
        HttpServletRequest request = webContext.getHttpServletRequest();
        HttpServletResponse response = webContext.getHttpServletResponse();
           System.out.println("00:"+request.getContextPath());
               TabUser operator = new TabUser();
             operator.setUsername(name);
             operator.setPassword(password);
             List<TabUser> userlist = userService.findUser(operator);
             System.out.println("11");
             if(userlist.size()==0){
                 
                 request.setAttribute("msg","1");
                 System.out.println("msg:"+request.getAttribute("msg"));
                 System.out.println("22");
                 return false;
                 
             }else{
                 System.out.println("33");
                 request.setAttribute("msg","2");
                 System.out.println("msg:"+request.getAttribute("msg"));
                return true;
//                   String html = webContext.forwardToString("/welcome.jsp");
//                   return html; 
             }

       }



jsp获取request.getAttribute("msg") msg为空这是什么原因?这window.location.href="welcome.jsp"有问题吗?

------解决方案--------------------
//dwr将要在前台调用的返回某个页面数据的方法 destURL:目标页面
public String getInclude(String destURL) throws ServletException, IOException{
//取得webapp上下文对象
org.directwebremoting.WebContext web= WebContextFactory.get();
//得到servlet中的request/response对象
javax.servlet.http.HttpServletRequest request=web.getHttpServletRequest();
javax.servlet.http.HttpServletResponse response=web.getHttpServletResponse();
//在此可提取request中相关请求参数...
//取得session对象
javax.servlet.http.HttpSession session=request.getSession();
//在此通过session做用户登陆等验证....
  
//返回页面结果
return web.forwardToString("/"+destURL);
}
------解决方案--------------------
楼主,dwr 可以直接返回对象,为何要用request返回,没用过,不清楚,

难道返回对象都不能满足楼主的要求吗?