There are many ways for a filter to modify a request or response. For example, a filter can add an attribute to the request or can insert data in the response. In the Duke's Bookstore example, HitCounterFilter inserts the value of the counter into the response.A filter that modifies a response must usually capture the response before it is returned to the client. To do this, you pass a stand-in stream to the servlet that generates the response. The stand-in stream prevents the servlet from closing the original response stream when it completes and allows the filter to modify the servlet's response.public void doFilter(ServletRequest request,     ServletResponse response, FilterChain chain)     throws IOException, ServletException 
{
    .....//you can handle response object
    //PrintWriter out = response.getWriter();
    chain.doFilter(request,response);}

解决方案 »

  1.   

    操!  这样能行吗?  晕倒!  难道要过滤器载入所有的JSP文件进行匹配和替换?
       就算技术上可行,性能一定顶不住!  老大,用其他方法吧!  
       
      

  2.   

    楼上的注意你的用词!难道你不知道,Filter可以配置过虑的URL???
    <url-pattern>/xxx.jsp</url-pattern>
      

  3.   

    他要替换掉JSP页面中的文本,  难道不需要将整个JSP页面都读入内存吗?
          不放入内存,怎么查找要替换的文本?