Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / General / October 2006

Tip: Looking for answers? Try searching our database.

Quick Servlet question: meaning of getPathInfo()

Thread view: 
David Lee Lambert - 10 Oct 2006 21:09 GMT
What is the purpose of javax.servlet.http.HttpServlet.getPathInfo()?

I wanted to build a servlet that stores a virtual filesystem in
an SQL database.  It just has one class,  which overrides doGet and doPut
so far.  Here's what WEB-INF/web.xml looks like:

<web-app>
<servlet>
<servlet-name>fs</servlet-name>
<description>Allows GET, PUT, DELETE of virtual files</description>
<servlet-class>com.lmert.slet.FileDB</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>fs</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>
</web-app>

If I request

http://some.host:8080/slet/x/y/z/a.txt

with a web-browser,  I need the relative path "x/y/z/a.txt".  However,
getPathInfo() always returns an empty string.  Is there some other method
I should use instead?  Is it possible to do this?


Signature

PGP key posted on website ... http://www.lmert.com/people/davidl/

Lothar Kimmeringer - 10 Oct 2006 23:01 GMT
> What is the purpose of javax.servlet.http.HttpServlet.getPathInfo()?

If the URL to your servlet is e.g.
http://www.example.com/path/to/servlet/MyServlet
the servlet will also be called if you use the URL
http://www.example.com/path/to/servlet/MyServlet/something/else.txt

In that case the Path-Info is
/something/else.txt

> with a web-browser,  I need the relative path "x/y/z/a.txt".  However,
> getPathInfo() always returns an empty string.  Is there some other method
> I should use instead?  Is it possible to do this?

Without trying myself: Look into
http://java.sun.com/j2ee/1.4/docs/api/javax/servlet/http/HttpServletRequest.html
There are a couple of methods and I think getContextPath should
return the part you need.
Another way would be getRequestURL and take the part for yourself.

Regards, Lothar
Signature

Lothar Kimmeringer                E-Mail: spamfang@kimmeringer.de
              PGP-encrypted mails preferred (Key-ID: 0x8BC3CD81)

Always remember: The answer is forty-two, there can only be wrong
                questions!

as4109@wayne.edu - 11 Oct 2006 09:21 GMT
Lothar Kimmeringer ha escrito:

> > What is the purpose of javax.servlet.http.HttpServlet.getPathInfo()?
>
[quoted text clipped - 5 lines]
> In that case the Path-Info is
> /something/else.txt

Thanks for the attempted advice.  Here is what I did to solve it:  I
changed

     <url-pattern>/</url-pattern>

to

     <url-pattern>/*</url-pattern>

I'm not sure if this behavior is specific to Tomcat,  but it appears
that,  if the url-pattern only partially matches,  the servlet still
gets called, but PATH_INFO will not contain any unmatched path
components up to the query string.


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.