Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

can I do this in servlet-mapping?

 
Ernesto Leyva
Ranch Hand
Posts: 62
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello

Somebody know if I can do this in the DD:

<servlet>
<servlet-name>MyServlet</servlet-name>
<servlte-class>foo.MyServlet</servlte-class>
</servlet>
<servlet-mapping>
<servlet-name>MyServlet</servlet-name>
<url-pattern>MyServlet.do</url-pattern>
<url-pattern>MyServletAlias1.do</url-pattern>
<url-pattern>/Alias/*</url-pattern>
</servlet-mapping>
 
Marc Peabody
pie sneak
Sheriff
Posts: 4727
Mac Ruby VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
No, that will violate the dtd's definition for web.xml. See this:
<!ELEMENT servlet-mapping (servlet-name, url-pattern)>

For each servlet-mapping you must have exactly one servlet-name and one url-pattern.

However, you could accomplish what you wanted by using multiple servlet-mapping tags that all contain the same value for servlet-name but with different url-pattern values.
 
Ernesto Leyva
Ranch Hand
Posts: 62
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks so that means I can do this

<servlet>
<servlet-name>MyServlet</servlet-name>
<servlte-class>foo.MyServlet</servlte-class>
</servlet>
<servlet-mapping>
<servlet-name>MyServlet</servlet-name>
<url-pattern>MyServlet.do</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>MyServlet</servlet-name>
<url-pattern>MyServletAlias1.do</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>MyServlet</servlet-name>
<url-pattern>/Alias/*</url-pattern>
</servlet-mapping>
 
Frederic Esnault
Ranch Hand
Posts: 284
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes.

But what you did first will be possible in J2EE 1.5 (servlet spec 2.5).

But don't think this way for SCWCD 1.4
 
Ernesto Leyva
Ranch Hand
Posts: 62
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yeah I think J2ee 1.5 got it right. the first way seems a more optimum way to do it.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic