• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

ServletMapping

 
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello all,
I have a question about servlet mapping.
I have this mapping in my web.xml:
<servlet-mapping>
<servlet-name>Servlet1</servlet-name>
<url-pattern>*.jsp</url-pattern>
</servlet-mapping>
and i have a jsp page called test.jsp in a directory called jsp
so the full request path to that jsp is
http://address ort/scwcd/jsp/test.jsp
where scwcd is the web application name.
from what i understood from the exam kit, the container will first try to match the request URI to a servlet mapping. if it finds a match the complete request URI (except the context path) is the servlet path. ( page 76 exam kit).
it will then recursively match the longest path by stepping down the request URI path ree a directory at a time. then move to step 3 where if the last node fof the request URI contains an extension , the container will tri to match it to a servlet that handles requests for the specified extension.
according to this, I think a request on that form..
http://address ort/scwcd/jsp/test.jsp
should be sent to Servlet1.
but that doesn't happen. I get the test.jsp page and not Servlet1.
 
Sheriff
Posts: 4313
Android IntelliJ IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Try changing your file name to "test.blah"
and adjust your sevlet mapping to this:
<servlet-mapping>
<servlet-name>Servlet1</servlet-name>
<url-pattern>*.bhah</url-pattern>
</servlet-mapping>
and hit it with the URL.... /scwcd/jsp/test.blah
Does the page get served up by Servlet1?
I'm guessing your Application Server is somehow overriding your configuration to have the JSP served up by your servlet, rather than by the app server itself.
 
Ranch Hand
Posts: 163
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Try
<servlet-mapping>
<servlet-name>Servlet1</servlet-name>
<url-pattern>/jsp/*.jsp</url-pattern>
</servlet-mapping>
this should work.
http://host/scwcd/jsp/test.jsp

Amer
 
Amer Khan
Ranch Hand
Posts: 163
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
In the above url "scwcd" is the ApplicationPrefix
registered in the server.xml (<Context path="/scwcd" docBase="location of the application" debug="0" />
The path name serves as the document root for the serving resources within the application.
if you want the location of the application to be outside Tomcat(container)
change docBase to point to that location.
for example <Context path="/scwcd" docBase="d:/someDir/scwcd " />
access it by using http://localhost:8080/scwcd/servet/myServlet
if you disable the 'invoker' servlet
then use ----/scwcd/myServlet
 
reply
    Bookmark Topic Watch Topic
  • New Topic