aspose file tools*
The moose likes Web Component Certification (SCWCD/OCPJWCD) and the fly likes Servlet Path/Path Info what for ? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Soft Skills this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Certification » Web Component Certification (SCWCD/OCPJWCD)
Bookmark "Servlet Path/Path Info what for ?" Watch "Servlet Path/Path Info what for ?" New topic
Author

Servlet Path/Path Info what for ?

cs flyer
Greenhorn

Joined: Nov 05, 2002
Posts: 3
Hi, I'am new to Servlet and studying SCWCD by reading Deshmukh/Malavia 's exam study kit.
In section 5.2.4 of the book, Mapping of ServletURL to Servlet Path and Path Info are discribed. Could anyone tell me what is the use of Servlet Path and Path Info as it seems the use of these "paths" are not explained. Why take the trouble to extract them from the servlet URL ?
g madhava
Ranch Hand

Joined: Sep 14, 2001
Posts: 85
CS:
Declaratively It's easy to maintain/establish the rules of URL mapping to the servlets in a DD.
Programmatically one could determine from which URL the request had come,if one comes to know about the pathInfo.
Any more ideas ?
Peter den Haan
author
Ranch Hand

Joined: Apr 20, 2000
Posts: 3252
Remember that in the web.xml file, servlet definition and servlet mapping are distinct. This means that a single servlet can be mapped to more than one URL. When you do this, you probably want the servlet to behave differently depending on the URL used. That is what you need getServletPath() for.
Example: you have a servlet "documentServlet" which serves up documents from a library stored in a database. It is mapped to both "/documents/public" and "/documents/secret" (obviously the "/documents/secret" path is restricted using web.xml security settings). Depending on which path is used, the servlet needs to use a different database to read documents from. You might have a little configuration file for the servlet allowing you to associate databases with any number of paths.
Wildcard servlet mappings are a great way to set up virtual filesystems. The servlet takes the extra path information and interprets it in some way; from the outside world it looks like an entire filesystem lives underneath the servlet. Of course here is where getPathInfo() kicks in, because that's how you find out about the wildcard bit of the mapping.
Let's continue our previous example. Say the documentServlet is mapped to "/documents/public/*". You could request the document "/documents/public/employment/policy.doc". The servlet would see a servlet path of "/documents/public", so it would know to access the public documents database. It would also see path info "/employment/policy.doc", and turn this into a primary key for the database query so that the right document is retrieved.
An end user would know nothing about this. (S)he would simply know that documents are living in a filesystem under "/documents". Better even, if you would implement the WebDAV protocol in your servlet, this filesystem would look just like any other Windows folder, with no hint that this stuff is actually living in a database. But WebDAV would take us outside the realm of the SCWCD exam, so I'll stop right here
- Peter
[ November 07, 2002: Message edited by: Peter den Haan ]
cs flyer
Greenhorn

Joined: Nov 05, 2002
Posts: 3
Thanks Guys, I get it now.
So these "paths" are nothing to do with the directory path location of servlet class file location.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Servlet Path/Path Info what for ?