Recent projects have a problem, is to get the last page connection address, I use the Internet Explorer, in the use of LOCATION.HREF connection to the new address, in the new address page with Document.referrer method to obtain the original address, I tested the next, with the use of Firefox and Google are ok. Some IE version can, some do not support, with the help of the teacher, found the solution on the Internet.
This is my product-view.jsp page, I click on the checkout need to determine whether there is a user ID, if not, I will let him log in first,gotuurl () in the URL is you go to the target page, this method creates a a tag, and then automatically trigger the Click event to go to the target page,
function Goumai (userid,proid,proprice,number) {
Alert ("Please login first!") ");
Gotourl ("/ebuy/login.jsp");
}
function Gotourl (URL) {
var referlink = document.createelement (' a ');
Referlink.href = URL;
Document.body.appendChild (Referlink);
Referlink.click ();
}
At this time the target page login.jsp can get referrer (previous page address);
$ (function () {
var address=document.referrer;
$ ("#yincang"). attr ("value", address);
}
)
Then landing the page and then go to the Servlet 's loginjudge page, just my login With the form submission I can use the hidden field to transfer the address of the previous page to the loginjudge page, and then return to the original page with judgment.
if (address!= "") {
Response.sendredirect (address);
Return
}
If there is no form validation, the way the servlet takes referrer is:
String url= request.getheader ("Referer");
System.out.println (URL);
String refer=url.substring (Url.indexof (Request.getcontextpath ()));
Response.sendredirect (refer);
Because at this time did not learn asynchronous commit, only with this stupid way, of course, Login page processing will have a lot of bugs, such as you failed to log in, or after the registration failed to enter even if successful, get still this page can not jump, judge is very troublesome.
of the test
Localtion.href and <jsp:forward page= "login.jsp" ></jsp:forward> can not be delivered in some ie browsers referrer.
Java Web project developed to get the last page connection address problem