Win a copy of Spark in Action this week in the Open Source Projects forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Bear Bibeault
  • Ron McLeod
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Tim Cooke
  • Liutauras Vilda
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • fred rosenberger
  • salvin francis
Bartenders:
  • Piet Souris
  • Frits Walraven
  • Carey Brown

Servlet Mapping Tag

 
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?
 
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
 
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).]
 
Something about .... going for a swim. With this tiny ad ...
Thread Boost feature
https://coderanch.com/t/674455/Thread-Boost-feature
    Bookmark Topic Watch Topic
  • New Topic