这是因为struts2的过滤器,解决方法是自定义一个过滤器
新建一个过滤器的类,代码:
1 package com.filter; 2 3 import java.io.IOException; 4 5 import javax.servlet.FilterChain; 6 import javax.servlet.ServletException; 7 import javax.servlet.ServletRequest; 8 import javax.servlet.ServletResponse; 9 import javax.servlet.http.HttpServletRequest;10 11 import org.apache.struts2.dispatcher.ng.filter.StrutsPRepareAndExecuteFilter;12 13 public class EditorStrutsFilter extends StrutsPrepareAndExecuteFilter{14 public void doFilter(ServletRequest req, ServletResponse res,15 FilterChain chain) throws IOException, ServletException {16 HttpServletRequest request = (HttpServletRequest) req;17 String url = request.getRequestURI(); 18 System.out.println(url); 19 if (url.contains("/jsp/")) { 20 System.out.println("使用自定义过滤器"); 21 chain.doFilter(req, res); 22 }else{ 23 System.out.println("使用默认过滤器"); 24 super.doFilter(req, res, chain); 25 }26 }
之后在web.xml里面配置struts2过滤器
1 <filter>2 <filter-name>struts2</filter-name>3 <filter-class>com.filter.EditorStrutsFilter</filter-class>4 </filter>5 <filter-mapping>6 <filter-name>struts2</filter-name>7 <url-pattern>/*</url-pattern>8 </filter-mapping>
注意,如果有
1 <filter>2 <filter-name>struts2</filter-name>3 <filter-class>org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter</filter-class>4 </filter>
要将其删除
最后,希望大家转载请注明出处,尊重别人的劳动成果http://my.oschina.net/jiangli0502/blog/210263
新闻热点
疑难解答