先看一下struts2 的web.xml文件:
org.apache.struts2.dispatcher.FilterDispatcher
在请求应用时,struts2将会截获所有请求,对于servlet请求将不能够正常相应,是struts2把servlet当成action了,因为servlet和action都是没有后缀的
解决方法目前有四种:
方法1:统一在servlet后面加上.servlet(包括web.xml配置文件中和页面上使用servlet的地方)
方法2:继承StrutsPrepareAndExecuteFilter,实现以下两个方法。
public void init(FilterConfig filterConfig) throws
ServletException {
..............................
}
public void doFilter(ServletRequest request, ServletResponse response,
FilterChain chain) throws
IOException, ServletException {
...............................
if(url.contain("servlet")){
((HttpServletResponse) response).sendRedirect(redirectUrl);
}
super.doFilter(request, response, chain);
}
方法3:修改拦截页面配置
原:
org.apache.struts2.dispatcher.FilterDispatcher
/*
现:
servlet的请求路径不必改变
方法4:在struts.xml文件中修改