struts2拦截器-自定义拦截器,放行某些方法(web.xml配置)
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了struts2拦截器-自定义拦截器,放行某些方法(web.xml配置)相关的知识,希望对你有一定的参考价值。
一、web.xml配置
<filter>
<filter-name>encodingFilter</filter-name>
<filter-class>org.springframework.web.filter.CharacterEncodingFilter</filter-class>
<init-param>
<param-name>encoding</param-name>
<param-value>UTF-8</param-value>
</init-param>
</filter>
<filter-mapping>
<filter-name>encodingFilter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
<filter>
<filter-name>struts2</filter-name>
<filter-class>com.appdept.servlet.MyStrutsFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>struts2</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
二、自定义拦截器
public class MyStrutsFilter extends StrutsPrepareAndExecuteFilter {
public void doFilter(ServletRequest req, ServletResponse res,
FilterChain chain) throws IOException, ServletException {
HttpServletRequest request = (HttpServletRequest) req;
String url = request.getRequestURI();
if (url.contains("PDFServer.jsp")) {
/*这两句在我的项目中是为了防止乱码,可以不用管
req.setCharacterEncoding("UTF-8");
res.setCharacterEncoding("UTF-8");*/
chain.doFilter(req, res); //直接跳过
}else{
/*req.setCharacterEncoding("UTF-8");
res.setCharacterEncoding("UTF-8");*/
super.doFilter(req, res, chain); //chain继续进下一个拦截器
}
}
}
以上是关于struts2拦截器-自定义拦截器,放行某些方法(web.xml配置)的主要内容,如果未能解决你的问题,请参考以下文章