Given a war file with the following structure
| – WEB-INF/classes/Myservlet.class
| – WEB-INF/lib/wf.jaf
Where wf.jar contains a valid web-fragment.xml and the following two classes: MyFilter1.class and
MyFiler2.class.
The web-fragment.xml is as follows:
The following are some code snippets:
When one access “/” of the above web application, which filters will be executed?
A.
No filters will be executed.
B.
MyFilter1
C.
MyFilter2
D.
MyFilter1 and MyFilter2
Explanation:
Note:
* <filter-mapping>
This tag specifies a filter name, and either a URL mapping or servlet name, for a filter that has
been defined with the <filter> tag.Multiple <filter-mapping> tags can be specified for a single <filter>, providing different URL
patterns. See the <url-pattern> tag for examples.
The <filter-mapping> has two required elements:
<filter-name> – the filter name, as specified in the <filter-name> element of the <filter> tag
Either a <url-pattern> or a <servlet-name>.
If a servlet name is specified, the filter will be called whenever the specific servlet is called.
Why not D? Metadata-complete in web-fragment.xml disable scanning annotation in wb.jar classes.
C is the answer
If there’s a lot of jars in WEB-INF/lib then startup of the servlet container could be significantly slow because every single class file in every single JAR file has to be scanned. We can turn off jar scanning for annotation by using metadata-complete=”true” in web.xml
http://www.logicbig.com/tutorials/java-ee-tutorial/java-servlet/servlet-annotations/