我有一个JSF应用程序,由于某些原因,我需要在浏览器返回按钮上刷新页面。我尝试实现Force JSF中给出的解决方案,通过BalusC的链接或返回按钮打开时刷新页面/视图/表单,唯一的区别是我的应用程序使用servlet 2.5版本运行,所以我在web. xml中做了如下映射
<?xml version="1.0" encoding="UTF-8"?>
http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"id="WebApp_ID"version="2.5"
<filter>
<filter-name>cacheFilter</filter-name>
<filter-class>com.gaic.lpsr.utilclasses.NoCacheFilter.java</filter-class>
</filter>
<filter-mapping>
<filter-name>cacheFilter</filter-name>
<servlet-name>FacesServlet</servlet-name>
</filter-mapping>
我的过滤类是
public class NoCacheFilter implements Filter {
@Override
public void doFilter(ServletRequest req, ServletResponse res, FilterChain chain) throws IOException, ServletException {
HttpServletRequest request = (HttpServletRequest) req;
HttpServletResponse response = (HttpServletResponse) res;
if (!request.getRequestURI().startsWith(request.getContextPath() + ResourceHandler.RESOURCE_IDENTIFIER)) { // Skip JSF resources (CSS/JS/Images/etc)
response.setHeader("Cache-Control", "no-cache, no-store, must-revalidate"); // HTTP 1.1.
response.setHeader("Pragma", "no-cache"); // HTTP 1.0.
response.setDateHeader("Expires", 0); // Proxies.
}
chain.doFilter(req, res);
}
@Override
public void destroy() {
// TODO Auto-generated method stub
}
@Override
public void init(FilterConfig arg0) throws ServletException {
// TODO Auto-generated method stub
}
// ...
}
当我尝试在tomcat服务器(版本6.0.29)部署应用程序时,我得到以下错误。
SEVERE: Exception starting filter cacheFilter
请指导我如何解决这个问题。
在web. xml:)中犯了愚蠢的错误。通过删除解决。过滤器映射中的java扩展
<filter-class>com.gaic.lpsr.utilclasses.NoCacheFilter</filter-class>