[context] tomcat 7 - java 1.7
Hey everyone; I'm facing with stranges working. In my web.xml file, I mapped request like this :
web.xml
<web-app>
<filter>
<filter-name>filter</filter-name>
<filter-class>demo.DemoFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>filter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
<servlet>
<servlet-name>Servlet</servlet-name>
<servlet-class>demo.DemoServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>Servlet</servlet-name>
<url-pattern>/*</url-pattern>
</servlet-mapping>
</web-app>
DemoFilter.java (implements Filter)
@Override
public void doFilter( ServletRequest req, ServletResponse res, FilterChain chain )
throws IOException, ServletException
{
try
{
chain.doFilter(req, res);
}
catch ( Exception e )
{
System.err.println("error");
((HttpServletResponse) res).setContentType("text/html");
((HttpServletResponse) res).setStatus(HttpServletResponse.SC_NOT_FOUND);
res.getWriter().write("foo");
}
}
DemoServlet.java (extends HttpServlet)
@Override
protected void doGet( HttpServletRequest req, HttpServletResponse resp )
throws ServletException, IOException
{
System.err.println(req.getRequestURI());
throw new RuntimeException("ERROR");
}
[1 = Expected result] First, when I tried to request "/foo/bar", the filter and the servlet were called (and the page display the word 'foo'). Console result :
/foo/bar
error
[2 = Unexpected result] Then, when I tried to request "/WEB-INF/foo/bar", nothing was called (my filter and my servlet were not hit) and I get a Tomcat error report :
HTTP Status 404 -
type Status report
message
description The requested resource is not available.
Apache Tomcat/7.0.30
EDIT : Here, I expected to get the following result :
/WEB-INF/foo/bar
error
I aim to use my Filter to handle Exception ("/WEB-INF" calls included).
- Why request which start with "/WEB-INF/" never hit filter/servlet mapped on "/*" pattern ?
- How can we solve this problem?
Thanks in advance!
PS : I would like to keep my current web.xml configuration ("url-pattern" = "/*" ; without using "error-page")
EDIT : My question was misunderstood. I don't want to serve file access under my "WEB-INF" directory. I want to serve every request with my Filter and Servlet (url-pattern='/*') even if the request URI start with "/WEB-INF/". Thanks !