Granny's Programming Pearls
"inside of every large program is a small program struggling to get out"
JavaRanch.com/granny.jsp
The moose likes Web Component Certification (SCWCD/OCPJWCD) and the fly likes ContextPath vs ServletPath Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Web Component Certification (SCWCD/OCPJWCD)
Bookmark "ContextPath vs ServletPath" Watch "ContextPath vs ServletPath" New topic
Author

ContextPath vs ServletPath

amarshi mohanty
Ranch Hand

Joined: Jul 01, 2008
Posts: 110
Hi,
As per the specification:
Context Path: The path prefix associated with the ServletContext that this servlet
is a part of. If this context is the “default” context rooted at the base of the web server’s
URL namespace, this path will be an empty string. Otherwise, this path starts with a’/’
character but does not end with a’/’ character.
Servlet Path: The path section that directly corresponds to the mapping which activated
this request. This path starts with a’/’ character.


I am not getting a clear picture of this info.
What is the difference ?


Thanks
Amarshi


SCJP (97%), SCWCD (95%))
Ankit Garg
Sheriff

Joined: Aug 03, 2008
Posts: 9291
    
  17

http://localhost:8080/context/myServlet

If you look at the request URL for a servlet mapped at the path /myservlet, here http:// is the protocol, localhost is the server name, /context is the context path and /myServlet is the servlet path.


http://localhost:8080/context/myServlet/random

If you look at the request URL for a servlet mapped at the path /myservlet/*, here /myServlet is the servlet path and /random is extra path info...


SCJP 6 | SCWCD 5 | Javaranch SCJP FAQ | SCWCD Links
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: ContextPath vs ServletPath
 
Similar Threads
How to get the servlet's requesting page ?
javax.servlet.forward.path_info
jsp not invoking servlet
"/" in context path
HFS Mack Exam Q22 - Page 772 - ResquestDispatcher - Is the answer correct?