JSP Uri/url-how to get the request URI, URL, and Context from a JSP

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.