get URL of request sender
My application is deployed as JavaScript working on some page and web application on tomcat somewhere else.
What I try to do now is find a way to determine if request was sent from gi开发者_如何学运维ven web page or was it sent from somewhere else (eg. from localhost - in this case I can not trush sent data).
When I tried to do that in my servlet - in doPost() - I was getting that servlet, as request sender url = http://localhost:8084/app/servlet
as a result of:
String domain = new URL(request.getRequestURL().toString()).toString();
System.out.println("url = " + domain);
What do I need to do, to get URL of page from which my script sent me data?
This information is available in the HTTP referer
header (yes, with the misspelling):
String referrer = request.getHeader("referer");
// ...
Please note that this is fully client-controlled -as everything else in a HTTP request. The client is able to change/spoof it. You should for sure not use it for sensitive business actions. Use it at highest for statistics or informal banners like "Hey, welcome visitor from Google! Your search keywords are highlighted here:" or like.
If I am not wrong, I think you're trying to reinvent Google Analytics. You may find this useful as well then: what's the proper way to write a js that will be included in other websites?
精彩评论