How to get referrer http header at Gwt Entrypoint
I Couldn't find any class/method which gives me access to 开发者_运维百科the referrer header in GWT. anyone knows about this?
See
Document.get().getReferrer()
Since you can't get the headers in javascript, I don't think you can get them in a GWT client either: Accessing the web page's HTTP Headers in JavaScript
Update:
Maybe you can update login.php to write out the referrer to a hidden input tag, maybe something like this:
<input type="hidden" name="referrer" name="referrer" value="<?php Print referrer_value ?>">
Then, in gwt you should be able to get the value using something like this:
InputElement elt = (InputElement)Document.get().getElementById("referrer")
String referrer = elt.getValue()
Note: This is untested code, and I'm not even sure that is valid php, but hope this helps!
I had the same question, but I made some changes to charge the header link tag dinamically. I used this code:
LinkElement link = Document.get().createLinkElement();
link.setHref("css/home.css");
I don't know if is the most graceful solution, but it works!
EDIT: If you need to modify any current element you should to do this:
NodeList<Element> links = Document.get().getElementsByTagName("link");
for(int i = 0; i < links.getLength(); i++){
LinkElement l = (LinkElement)links.getItem(i);
if( l.toString().contains("href_to_replace.css") ){
l.setHref("new_href.css");
break;
}
}
You can access to the referrer in JavaScript and pass it to Java (rather to the JavaScript compiled from Java). You need to define a JSNI (JavaScript Native Method) method in Java with a JavaScript definition. This code can access the document and window objects of the browser, although you need to respectively use $doc and $wnd variables for that purpose. More info at
https://developers.google.com/web-toolkit/doc/latest/DevGuideCodingBasicsJSNI
You can get the full URL String like so:
String url = Document.get().getURL();
get the index of a question mark and parse it by yourself
精彩评论