使用HttpServletRequestWrapper时无法发送jsp参数?

时间:2012-04-09 08:40:13

标签: java jsp tomcat servlets

我使用Tomcat7。我的项目结构是:

  • as1.jsp

  • as2.jsp

web.xml的内容是:

  <filter-mapping>  
            <filter-name>filter1</filter-name>  
            <url-pattern>/as1.jsp</url-pattern>  
        </filter-mapping>

filter1在HttpServletRequestWrapper中使用:

...  
   RequestWrapper requestWrapper = new RequestWrapper(req);  
   requestWrapper.setParameter("params", new String[]{Item.getParams()});   
   chain.doFilter(requestWrapper, response);  
......  

as1.jsp的内容是:

hi <br/>  
<jsp:include page="as2.jsp">  
        <jsp:param name="test" value="true" />            
</jsp:include>  

as2.jsp的内容是:

as2 runed  
<br/>  
test:<%= request.getParameter("test") %>  

当我部署项目时,我得到了这个结果:

hi  
as2 runed  
test:null  

并在HttpServletRequestWrapper中移除filter1时,我得到了正确的结果:

hi  
as2 runed  
test:true  

请帮助我,request.getParameter("test")如何HttpServletRequestWrapperfilter1进行对比? 谢谢。

1 个答案:

答案 0 :(得分:0)

看起来Filter RequestWrapper覆盖了.getParameter()方法而未委托原始请求。