Get Absolute URL Path in java

Is there a way to get the absolute URL path (http: // localhost: 8080 / myApp) in java. Scenario: I need to connect to the csv file located on the tomcat server. The statement works well if I enter the absolute path, but is there a solution for retrieving the URL using getAbsolutePath (). Sorry if I'm wrong.

Connection conn = DriverManager(getConnection("jdbc:relique:csv:/home/apache-tomcat-6.0.26/webapps/myApp/"))

Thanks in advance.

+5
source share
3 answers

You can use ServletContext.getRealPath()one that does exactly what you want.

Please note that this does not necessarily work in all situations. For example, if your Tomcat is configured to deploy a .war file without unpacking it, it will return null.

+9

JAVA.

May be getServletContext().getContextPath() is something you are looking for

EDIT:
Or may be getRealPath()

0

Tomcat is not an http server. All tomcat links to link services, not files.

You will need to implement another service that will send the csv file on request if you want to receive it via any http url. A URL, for example http://localhost/myapp/input.csv, requires an HTTP server such as apache httpd.

(I hope I understood your question correctly ...)

-1
source

All Articles