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.