File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
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

ContextPath vs ServletPath

amarshi mohanty
Ranch Hand

Joined: Jul 01, 2008
Posts: 110
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 ?


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

Joined: Aug 03, 2008
Posts: 9465


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.


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:
subject: ContextPath vs ServletPath
It's not a secret anymore!