troubleshooting Question

Using URL path in jsp

Avatar of R7AF
R7AFFlag for Netherlands asked on
JavaJSPJava EE
16 Comments1 Solution550 ViewsLast Modified:
Say I have a webapp (http://mydomain.com/test/) with three files in a subdirectory (123):

1) test/123/index.jsp
2) test/123/data.jsp
3) test/123/test.jsp

Index.jsp reads data from data.jsp and test.jsp. It has the following code in it:

String dataUrl = "http://localhost:8080/test/123/data.jsp";
String tUrl = "http://localhost:8080/test/123/test.jsp";
URL dataAuth = new URL(dataUrl);
URL tAuth = new URL(tUrl);

What happens here is that it reads data from these files in the same folder. What I want is to be able to read data.jsp from a relative path (like: String dataUrl = "data.jsp";) or get the path name (test/123) from the request URL. Now I have to change the url for each folder where I use this code. I want this to be done dynamically. How can I do this?
Join the community to see this answer!
Join our exclusive community to see this answer & millions of others.
Unlock 1 Answer and 16 Comments.
Join the Community
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 16 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros