Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Getting absolute path of image file  RSS feed

 
Raghu Nathan
Ranch Hand
Posts: 44
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Ulf Dittmer
Rancher
Posts: 42970
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The ServletContext.getRealPath method can do this.

Since this is a servlet-related topic, I'll move it to the Servlets forum.
 
Raghu Nathan
Ranch Hand
Posts: 44
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks ...
I am trying to use this from my ActionClass - is there an alternative to ServletContext.getRealPath?
 
Raghu Nathan
Ranch Hand
Posts: 44
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 65826
134
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Are you trying to get the file path or the URL?
 
Raghu Nathan
Ranch Hand
Posts: 44
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 65826
134
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
All the information you need is available from the methods on the request.
 
Raghu Nathan
Ranch Hand
Posts: 44
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It is indeed! It was right under my nose! And I have used it earlier, never realized ....
Thanks for the help, Bear!
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!