• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

ContextPath vs ServletPath

 
amarshi mohanty
Ranch Hand
Posts: 110
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Ankit Garg
Sheriff
Posts: 9519
22
Android Google Web Toolkit Hibernate IntelliJ IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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...
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic