Java Web project developed to get the last page connection address problem

Source: Internet
Author: User

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

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.