Exclusive url-patterns in Tomcat web.xml descriptor

旧巷老猫 提交于 2019-12-24 07:26:14

问题


I am trying to redirect erroneous page requests - 404 errors - to a custom error page. In order for my servlet, instead of the root servlet, to handle these requests, I entered the following url-pattern:

<url-pattern>/</url-pattern>

Unfortunately, this also catches embedded requests for files like *.js, *.css, *.png, *.jpg, and other such files. Is there a way in the deployment descriptor to specify an exclusive pattern? Say, "everything EXCEPT requests with x extension"?

Or is there another way around this that I'm not seeing?


回答1:


You can just declare an error page for HTTP 404 errors in the DD as follows.

<error-page>
  <error-code>404</error-code>
  <location>/notFound.jsp</location>
</error-page>

The container (Tomcat in your case) will then capture any HTTP 404s and forward them on to the page you specify (/notFound.jsp in the example above).

There's some documentation at Sun, and some more at Google Code.



来源:https://stackoverflow.com/questions/1495228/exclusive-url-patterns-in-tomcat-web-xml-descriptor

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!