This week's book giveaway is in the Agile and Other Processes forum.
We're giving away four copies of The Little Book of Impediments (e-book only) and have Tom Perry on-line!
See this thread for details.
Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Servlet Mapping Tag

 
Anonymous
Ranch Hand
Posts: 18944
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In web.xml, I have following xml
<servlet>
<servlet-name>
CompressionFilterTestServlet
</servlet-name>
<servlet-class>
compressionFilters.CompressionFilterTestServlet
</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>
CompressionFilterTestServlet
</servlet-name>
<url-pattern>
/CompressionTest
</url-pattern>
</servlet-mapping>
Instead of calling servlet http://localhost:80/CompressionFilterTestServlet, I can use http://localhost:80/CompressionTest. Is that what <servlet-mapping> means?
 
Marcos Maia
Ranch Hand
Posts: 977
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
the short answer is yes, but I have some comments about it.
you�re not required to write the port if its 80, that�s the default for your browser, so http://localhost/CompressionTest should be fine, I allways deploy my servlets in a war file and doing so I have to write the name of the war in the url:
ex:
you have build a example.war and packaged your servlet in it, you should do: http://localhost/example/CompressionTest
I can�t remember now how to do if you deploy your servlet without packagin it in a war file.
regards.
 
Anonymous
Ranch Hand
Posts: 18944
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Main application of Servlet mapping is you can make your Servlet to be invoked for different patterns of the request.
for ex:
<servlet-mapping>
<servlet-name>
CompressionFilterTestServlet
</servlet-name>
<url-pattern>
/CompressionTest/*
</url-pattern>
</servlet-mapping>
Then all the urls like http://<webserver>/<contextPath>/CompressionTest/ANYTHINGHERE will invoke CompressionFilterTestServlet servlet, irrespective of the value of the ANYTHINGHERE
Sridhar
 
Manish Singhal
Ranch Hand
Posts: 104
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If what SridharS is saying is TRUE, then thats a new learning for me.
Thanks
Manish
 
Marcos Maia
Ranch Hand
Posts: 977
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi, this is taken from the servlet2.3 specs pg.77
Consider the following set of mappings:
The following behavior would result:
Table SRV.11-1 Example Set of Maps
path pattern | servlet
/foo/bar/* | servlet1
/baz/* | servlet2
/catalog | servlet3
*.bop | servlet4
Table SRV.11-2 Incoming Paths applied to Example Maps
incoming path servlet handling request
/foo/bar/index.html | servlet1
/foo/bar/index.bop | servlet1
/baz | servlet2
/baz/index.html | servlet2
/catalog | servlet3
/catalog/index.html | �default�servlet
/catalog/racecar.bop | servlet4
/index.bop | servlet4
regards.
[This message has been edited by Marcos Maia (edited October 24, 2001).]
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic