JSP to get a summary of the current access URL, url parameters and other information.

Source: Internet
Author: User

the relevant code in the JSP page:
<%
String path = Request.getcontextpath ();
String basepath = request.getscheme () + "://" +request.getservername () + ":" +request.getserverport () +path+ "/";
String url = "/http" + request.getservername () + ":" + request.getserverport () + Request.getcontextpath () +req Uest.getservletpath (). substring (0,request.getservletpath (). LastIndexOf ("/") +1);

if (request.getquerystring ()!=null)
{
url+= "?" +request.getquerystring ();
}
System.out.println ("Path:" +path);
System.out.println ("BasePath:" +basepath);
System.out.println ("URL:" +url);

SYSTEM.OUT.PRINTLN ("url parameter:" +request.getquerystring ());
%>

Results of output after access:
1. This is without parameters
Path:/cs
basepath:http://localhost:8080/cs/
url:http://localhost:8080/cs/
URL parameter: null
2. When with parameters
Path:/cs
basepath:http://localhost:8080/cs/
Url:http://localhost:8080/cs/?userid=3
URL parameter: userid=3

In order for the servlet to jump to the URL with parameters, it took a long time to find the exception. It turned out to be so simple. Save the URL to the session, and then remove it when it is unusual to add it up.
String url = session.getattribute ("url");
Out.println ("<script>alert" is wrong. '); window.location.href= ' "+url+" ';</script> ");

JSP to get a summary of the current access URL, url parameters and other information.

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.