How to use request.getHeader ("Referer")

In my current project, I have a shopping basket integrated with the main site. Now I need to create some mini-sites to display the data received from the main site. When the user clicks the Buy Now button on the mini-site, he should be redirected to the main shopping cart. But when the user clicks the โ€œContinue shoppingโ€ button, this should be sent back to the page of the mini-site where he was viewed. Both sites will have 2 different domain names. Can I send him back to the page where he was browsing us?

request.getHeader("Referer") 

It will be 2 different web applications, so request.getHeader("Referer") will help send it back to the page where it was browsing.

Send me some suggestions.

+7
source share
2 answers

You should not rely on Referer for the logic of your application, since sending Referer can be blocked by firewalls or browser configurations.

Consider instead the returned URL instead of the parameter: http://mainsite.com/shoppingCart?returnTo=http%3a%2f%2fminisite.com%2foriginalPage .

Also, make sure returnTo points to your site to avoid potential security issues.

+13
source

this seems to be the correct syntax:

 getHttpServletRequest().getHeader("Referer")) 
-one
source

All Articles