问题
I have a application which is deployed on tomcat with servlet version 2.4, and its working nicely.
When i tried to deploy the same application on websphere, deployment failed. I found that multiple url-patterns causing the issue.
example code:-
<filter>
<filter-name>ABCD</filter-name>
<filter-class>com.x.y.filters.ABCD</filter-class>
</filter>
<filter-mapping>
<filter-name>ABCD</filter-name>
<url-pattern>/A/*</url-pattern>
<url-pattern>/B/*</url-pattern>
<url-pattern>/C/*</url-pattern>
<url-pattern>*.jsp</url-pattern>
</filter-mapping>
So my question is that why servlet version 2.4 is not working with websphere (NOTE: if i use 3.0 its working). In my understanding servlet version specific to what we are deploying.
I am using websphere 8 which supports 3.0 and lower servlet versions.
Please help me to understand better.
回答1:
You must have individual filter mapping for each url pattern:
<filter-mapping>
<filter-name>ABCD</filter-name>
<url-pattern>/A/*</url-pattern>
</filter-mapping>
<filter-mapping>
<filter-name>ABCD</filter-name>
<url-pattern>/B/*</url-pattern>
</filter-mapping>
Servlet 2.4 specification defines:
<xsd:choice>
<xsd:element name="url-pattern"
type="j2ee:url-patternType"/>
<xsd:element name="servlet-name"
type="j2ee:servlet-nameType"/>
</xsd:choice>
Servlet 2.5 introduced support for multiple occurences that is why it works in servlet 3.0 for you.
Tomcat 6 supports servlets 2.5 specification. The question is why multiple occurences of filter mapping works in it when web.xml
says that it is 2.4 version application. IMHO it is vendor specific "enhancement". They do not fullfill servlet specification contract. On the other hand you do not as well because your web.xml is not valid. They decided to ignore the specified version. WebSphere does what it shall - it rejects your invalid web.xml
.
来源:https://stackoverflow.com/questions/23057708/deployment-issue-with-multiple-url-patterns