This week's giveaway is in the EJB and other Java EE Technologies forum. We're giving away four copies of EJB 3 in Action and have Debu Panda, Reza Rahman, Ryan Cuprak, and Michael Remijan on-line! See this thread for details.
Duran Harris wrote:Can anyone explain what getContextPath() does??
And what interfaces/classes it is defined in?
getContextPath() returns the context of the request, if your web application is running on http://localhost:8080/DuranWebapps/Email.do than calling this getContextPath will return /DuranWebapps as you have request Email.do so whatever servlet mapped by you in DD for Email.do will have ContextPath /DuranWebapps that you deploy under your tomcat/webapps directory.
You can get it using request.getContextPath().
getContextPath() is declared in HttpServletRequest.java interface and
defined in HttpServletRequestWrapper.java
Jonathan put some nice colors which apparently you can't see. So here's the breakdown:
http://localhost:8088/SCWCD/ch1/info?param=value Context Path - /SCWCD
Servlet Path - /ch1
Path Info - /info
Query String - param=value
So even if I used request dispatchers the <url-patterns> still map my requests??
And to summarise :
Path-Info=Basically just the resource's physical name??
Servlet-Path=context-path+every single directory up to and including the directory containing the resource to which the request is forwarded.