Jsp request. getHeader ("referer ")

Source: Internet
Author: User
Tags php tutorial

Jsp tutorial request. getHeader ("referer ")


It is an http protocol, so any language that can develop web programs can be implemented. For example, in jsp:

Request. getHeader ("referer ");

The php Tutorial is $ _ SERVER ['http _ referer']. I will not give examples of other languages ).

What can it do? Here are two examples:

1. Prevent unauthorized connection. For example, I am a software download website. On the download page, I first use a referer to determine whether the previous page is my website. If not, it indicates that someone has stolen your download address.

2. For the security of e-commerce websites, I use referer on the pages that submit important information such as credit cards to determine whether the previous page is my own website. If not, it may be a form written by hackers, in order to skip the verification of special webpage effects on your previous page.

Notes for using referer:

If I enter a page with a referer in a browser, the return value is null (jsp). That is to say, the referer will only have content when it comes to the page by clicking the link from another page.

I did an experiment. For example, if my referercode is in a.jsp, the webpage is B .htm, and c.htm is a page with iframe. It embeds a. jsp in iframe. The token is sent to the server as a referer.

How to obtain the address of the previous page

OK. If the sending page is submitted in POST mode
This request. getHeader ("referer") is completely correct.
However, if the sending page is submitted in get mode, it may also contain parameters
Request. getHeader ("referer") returns a null value. How can this problem be solved?

Let's talk about my situation.
For example, each JSP page contains
<% @ Page errorPage = "../error. jsp" %>
If any problem occurs, the error. jsp page is displayed.
Error. jsp has a back button to return to the previous page.

In fact, history. back () can be used, but because the proxy server removes the cache, another method is required to implement this function.

Do you have any good methods and suggestions ?? Thank you.

Save the address to the request or session.

You do not understand <% @ page errorPage = "../error. jsp" %>
Otherwise, it is impossible to ask this question.

Sorry, it's okay to use request. getHeader for get.
Document. location = "xx. jsp".

Ask how to understand it ~ To be honest, I only know that errorpage is equivalent to a large catch.

However, you need to have a function to return to the upper-level page on this page.

OK. If the sending page is submitted in POST mode
This request. getHeader ("referer") is completely correct.

Related Article

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.