0

我有一个 JSF (IceFaces 1.8.2) 网站。我需要以下功能: 当显示特定的 JSF 页面时,我想将其 HTML 代码存储在数据库中。我尝试使用 Servlet 过滤器来捕获代码(使用 HttpResponseWrapper 对象,因为它写在 SUN 网页和很多教程中),但响应总是空的。有人可以帮助我吗?

这是doFilter:

public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain)
    throws IOException, ServletException {  

    Wrapper responseWrapper = new Wrapper((HttpServletResponse)response);
    chain.doFilter(request, responseWrapper);
    //I just want the output on stdout at the moment...
    System.out.println(responseWrapper.toString());
    PrintWriter out = response.getWriter();
    out.write(responseWrapper.toString()); 
    }

这是包装器:

public class Wrapper extends HttpServletResponseWrapper{
    private CharArrayWriter writer;
    public Wrapper(HttpServletResponse response){
        super(response);
        writer = new CharArrayWriter();
}

public PrintWriter getWriter(){
    return (new PrintWriter(writer));
}

public String toString(){
    return writer.toString();
}

public char[] toCharArray(){
    return (writer.toCharArray());
 }
}

和 web.xml:

<filter>
  <filter-name>MyFilter</filter-name>
  <filter-class>foo.myfilter</filter-class>
</filter> 
<filter-mapping>
  <filter-name>MyFilter</filter-name>
  <url-pattern>*.iface</url-pattern>
</filter-mapping>
4

1 回答 1

1

也许 JSF 发送一个重定向,或者使用response.getOutputStream()? 尝试在所有方法中设置断点HttpServletResponseWrapper以发现 JSF 调用的方法。

于 2012-08-18T22:33:24.190 回答