How to get the full path in jsp?

Can anyone suggest how to get the full path in jsp?

I am creating an image anywhere in the java class, and when I try to access this location path in jsp, it does not show the full path.

+4
source share
3 answers
<html> <head><title>Absolute Path</title></head> Absolute Path is:<%= getServletContext().getRealPath("/") %> </html> 

Hope this help helps you.

+5
source

You can use the real way.

  String webRootPath = application.getRealPath("/").replace('\\', '/'); 

or

  String webRootPath = getServletContext().getRealPath("/").replace('\\', '/'); 
+3
source

It is better to create a folder of your own resources inside the folder of your application and save all your resources (images in your case).

Then you can access it using this:

 String path=application.getRealPath("/resourcesfolder/image.jpg"); 
0
source

All Articles