This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes Servlets and the fly likes How to get DISK absolute path according URL Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "How to get DISK absolute path according URL " Watch "How to get DISK absolute path according URL " New topic
Author

How to get DISK absolute path according URL

liang sun
Ranch Hand

Joined: May 12, 2001
Posts: 51
How to get DISK absolute path according URL
Example: convert "http://sun:8080/a.jsp"
to "c:\aaa\a.jsp"
Tim Baker
Ranch Hand

Joined: Oct 04, 2003
Posts: 541
you can't unless you are inside that JSP page. Because you can map a context to anywhere on the disk you can't automatically know where it is. But if you are inside the JSP / Servlet you can use the context object and getRealPath to get the local path to the context.
[ November 09, 2003: Message edited by: Tim Baker ]

Kim Jong II (North Korea's Dear Leader) said:Nuclear weapons don't kill people, people kill people.
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60766
    
  65

If I understand Tim's reply, that's not completely correct. You can use getRealPath() from anywhere inside a web app to find the path of a resource anywhere within the web application. You do not need to be within the resource itself.
bear


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
 
 
subject: How to get DISK absolute path according URL
 
Similar Threads
Create file object for each assets item.
log4j error?
Relative URL specifications, JSP 1.2.1
absolute path Formfile upload
genarate PDf and save it on server