• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Servlet Path/Path Info what for ?

 
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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 ?
 
Ranch Hand
Posts: 85
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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 ?
 
author
Posts: 3252
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks Guys, I get it now.
So these "paths" are nothing to do with the directory path location of servlet class file location.
 
reply
    Bookmark Topic Watch Topic
  • New Topic