struts,根据要求清理查询字符串?

时间:2014-10-21 22:43:14

标签: java javascript jsp struts struts1

我使用的是Struts 1,只想清理每个请求的参数URL。

在请求中,例如:myapp.com/view.do?method=search

public ActionForward search(ActionMapping mapping, ActionForm form, 
        HttpServletRequest request, HttpServletResponse response)throws Exception{      
request.setAttribute("RESULT","PERU");
return mapping.findForward("home");
}

在转发中,网址相同(myapp.com/view.do?method=search)。

后来,我这样做了:

public ActionForward search(ActionMapping mapping, ActionForm form, 
        HttpServletRequest request, HttpServletResponse response)throws Exception{      
request.setAttribute("RESULT","PERU");
ActionForward af = new ActionForward(mapping.findForward("home"));
af.setRedirect(true);
return af;
}

我收到了网址:myapp.com/home.jsp,很好!但是,我失去了属性("结果")。

当我使用"重定向" Struts 1发出新请求,丢失所有属性。

还有什么其他形式的清理ActionForward中的网址?

2 个答案:

答案 0 :(得分:0)

如果您想将页面重定向到主页,只需返回mapping.findForward("home"),如下所示

public ActionForward search(ActionMapping mapping, ActionForm form, 
    HttpServletRequest request, HttpServletResponse response)throws Exception{      
    request.setAttribute("RESULT","PERU");


    return mapping.findForward("home");
}

答案 1 :(得分:0)

在进行重定向之前将属性保存到会话

public ActionForward search(ActionMapping mapping, ActionForm form, 
        HttpServletRequest request, HttpServletResponse response) throws Exception {      
  request.getSession().setAttribute("RESULT","PERU");
  ActionForward af = new ActionForward(mapping.findForward("home"));
  af.setRedirect(true);
  return af;
}