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

ServletMapping

 
Ayman Nour
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • 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.
 
Jessica Sant
Sheriff
Posts: 4313
Android IntelliJ IDE Java
  • Mark post as helpful
  • send pies
  • 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.
 
Amer Khan
Ranch Hand
Posts: 163
  • Mark post as helpful
  • send pies
  • 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
  • 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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic