aspose file tools
The moose likes Servlets and the fly likes Getting absolute path of image file Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


JavaRanch » Java Forums » Java » Servlets
Reply Bookmark "Getting absolute path of image file" Watch "Getting absolute path of image file" New topic
Author

Getting absolute path of image file

Raghu Nathan
Ranch Hand

Joined: Jan 16, 2006
Posts: 44
Hello all,
I have an image file that I need to be using in an external tool and the only way I can use that is through its absolute (url) path. So if my image can be accessed by

I need to be able to get the absolute path which might be:


How can I do this?

Before I finish, I do not know if this topic belongs here; if it does not then please do the needful to port it to the right forum. I apologize if that is the case.

Thanks.


Thanks ... Raghu
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 35438
    
    9
The ServletContext.getRealPath method can do this.

Since this is a servlet-related topic, I'll move it to the Servlets forum.


Android appsImageJ pluginsJava web charts
Raghu Nathan
Ranch Hand

Joined: Jan 16, 2006
Posts: 44
Thanks ...
I am trying to use this from my ActionClass - is there an alternative to ServletContext.getRealPath?
Raghu Nathan
Ranch Hand

Joined: Jan 16, 2006
Posts: 44
Hi
I tried doing this from my action class:



But I am getting NULL.
Is that the right way to use getRealPath? Please advise.

I am looking up online but I am not finding any answers.
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 56529
    
  14

Are you trying to get the file path or the URL?


[Smart Questions] [JSP FAQ] [Books by Bear] [Bear's FrontMan] [About Bear]
Raghu Nathan
Ranch Hand

Joined: Jan 16, 2006
Posts: 44
I want to get the URL for the image.
Let me explain the requirement, I am trying to use this image from an XSL file and there it will not take the relative path, but only the absolute path.
So I need to be able to reference the image as

From my Java code, I will be able to get the relative path of the image but I will need to know what is the application URL so that I can pass it appropriately to my XSL so that it can read the image properly and render it.

Thanks.
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 56529
    
  14

All the information you need is available from the methods on the request.
Raghu Nathan
Ranch Hand

Joined: Jan 16, 2006
Posts: 44
It is indeed! It was right under my nose! And I have used it earlier, never realized ....
Thanks for the help, Bear!
 
I agree. Here's the link: http://zeroturnaround.com/jrebel - it saves me about five hours per week
 
subject: Getting absolute path of image file
 
Similar Threads
Accessing File from ActionClass
sendRedirect problem
Accesing image files in java beans
Accessing a jpeg or gif in an unpacked war file
Multilevel context path for ROOT app does not work