错误1:
The servlets named [goodsServlet] and [LoginServlet] are both mapped to the url-pattern [*.exe] which is not permitted
at org.apache.tomcat.util.descriptor.web.WebXml.addServletMapping(WebXml.java:308)
原因:web.xml中 servlet的url-pattern应该保证唯一。确保一个请求地址只有一个响应。
但在filtle中 ,url-pattern值过滤的是某一类的请求地址信息。可以重复。
<servlet>
<servlet-name>goodsServlet</servlet-name>
<servlet-class>com.zkingsoft.servlet.GoodsServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>goodsServlet</servlet-name>
<url-pattern>*.exe</url-pattern>
</servlet-mapping>
<servlet>
<servlet-name>LoginServlet</servlet-name>
<servlet-class>com.zkingsoft.servlet.LoginServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>LoginServlet</servlet-name>
<url-pattern>LoginServlet.exe</url-pattern>
<url-pattern>*.exe</url-pattern>
<url-pattern>/LoginServlet.exe</url-pattern>
</servlet-mapping>
解决办法: 改掉servlet url-pattren配置重复的地址。
错误2:Server Tomcat v8.0 Server at localhost failed to start.
错误原因:servlet url-pattren精确设置没有加/;
java.lang.IllegalArgumentException: Invalid <url-pattern> LoginServlet.exe in servlet mapping
at org.apache.catalina.core.StandardContext.addServletMapping(StandardContext.java:3075)
at org.apache.catalina.core.StandardContext.addServletMapping(StandardContext.java:3050)
at org.apache.catalina.startup.ContextConfig.configureContext(ContextConfig.java:1372)
at org.apache.catalina.startup.ContextConfig.webConfig(ContextConfig.java:1176)
at org.apache.catalina.startup.ContextConfig.configureStart(ContextConfig.java:771)
at org.apache.catalina.startup.ContextConfig.lifecycleEvent(ContextConfig.java:305)
at org.apache.catalina.util.LifecycleSupport.fireLifecycleEvent(LifecycleSupport.java:117)
at org.apache.catalina.util.LifecycleBase.fireLifecycleEvent(LifecycleBase.java:90)
at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5065)
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
... 6 more
解决:检查sevlet mapping 下的servlet url-pattren 的值是否设置/
错误3:使用loginfiltle时给 .exe .jsp .html后缀的所有请求都拦截 。结果无法进入界面,所有页面都报404.
解决方法:在过滤器中添加如下代码:
if(path.indexOf("/login.html")>-1){//登录页面不过滤
arg2.doFilter(arg0, arg1);//递交给下一个过滤器
System.out.println(0);
return;
}
结果能够进入登录界面了,但是,我发现我登录页面按钮无效,疯狂的点击登录结果是刷新登录界面
原因是什么呢? 我忘记设置允许LoginServlet允许通过了。结果就是请求LoginServlet服务,loginfiltle检测到属于拦截内容,且不满足放行条件,自动跳转到login.html页面
添加:
if(path.indexOf("/LoginServlet.exe")>-1){//登录服务不过滤
arg2.doFilter(arg0, arg1);//递交给下一个过滤器
System.out.println(0);
return;
}