JSP Uri/url faq:how do I get a URI or URL from a JSP (the request URI or request URL)?
I was just working with a JSP, and trying to remember how to get information the can be very helpful inside of a JSP, SPE cifically how to determine the Context, URI, and URL from within a JSP.
To so end, here's the Java source code for a JSP I wrote that would display the Context, URI, and URL for this JSP when I T is accessed from a browser:
When I save the a file named uriTest.jsp
, place it in a context named that's test
already running on a Tomcat server on my Local computer, and then hits the URL for this JSP ( http://localhost:8080/test/uriTest.jsp
), I see the following output:
JSP uri, URL, contextrequest Context Path:/testrequest uri: /test/uritest.jsprequest URL: http://localhost : 8080/test/uritest.jsp
Information like this can is very helpful when doing a variety of things inside a JSP. For instance, with looking at the blog here at Devdaily.com/blog, I want to add some social bookmark links ing that, I can use the =request.getRequestURI()
or request.getrequesturl () = methods to get the URL information that I need to send to Digg, StumbleUpon, and others.
While I mentioned that I-ran this test from within Tomcat, you'll use these same java/jsp methods from within any servlet container, including Glassfish, JBoss, WebLogic, or WebSphere.
JSP Uri/url-how to get the request URI, URL, and Context from a JSP