将所有参数转发给JSP

时间:2016-01-05 15:58:47

标签: java jsp struts-1

现在我需要从url中获取参数并将它们放入请求中,但有没有办法自动执行此操作。即将所有url参数放入请求并转发到jsp而不编写如下代码?

private ActionForward managementView(ActionMapping actionMapping, ActionForm actionForm,
        HttpServletRequest request, HttpServletResponse response) {
    request.setAttribute("param1", request.getParameter("param1"));
    request.setAttribute("param2", request.getParameter("param2"));
    request.setAttribute("param3", request.getParameter("param3"));
    request.setAttribute("param4", request.getParameter("param4"));
    .....

    return actionMapping.findForward("managementView");
}

2 个答案:

答案 0 :(得分:1)

你可以尝试设置forward =" true"在相应的struts-config.xml文件中转发。

http://www.javapractices.com/topic/TopicAction.do?Id=181可以帮助您提供相同的详细信息。

答案 1 :(得分:0)

如果这对你有用

   protected void setRequestParameters(HttpServletRequest req) {
        Enumeration<String> requestEnumeration = req.getAttributeNames();
        while(requestEnumeration.hasMoreElements()){
            String paramName = requestEnumeration.nextElement();
            req.setAttribute(paramName, req.getAttribute(paramName));
        }
    }