Monday, June 3, 2024
 Popular · Latest · Hot · Upcoming
173
rated 0 times [  176] [ 3]  / answers: 1 / hits: 39229  / 12 Years ago, fri, june 1, 2012, 12:00:00

I am in process to capture Current URL as its being displayed in the browser's address bar in my JSP page and have few options to get it done.





In my current application, we are going to put web-server in front of our application server as than it seems that those values will be of not any use.



I have another way to take help of javascript's document.URL but i am not sure how reliable it is going to be.



I need to get the details about the location of the user and if I can use getRequestURI(), it will return me something like www.abc.com/abc/search.jsp.



In short, all I want to capture the URL being there in the address bar of the browser and save it in a hidden field of my JSP page.



I am not sure what is the best way to achieve this.


More From » java

 Answers
35

If you want a javascript solution, you can use window.document.location object and its properties:



console.log(window.document.location.protocol);
http:
console.log(window.document.location.host);
stackoverflow.com
console.log(window.document.location.port);

console.log(window.document.location.href);
http://stackoverflow.com/questions/10845606/get-current-url-in-webapplication
console.log(window.document.location.pathname);
/questions/10845606/get-current-url-in-webapplication


You can understand other parameters reading this article at MDN.


[#85219] Thursday, May 31, 2012, 12 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
ezequiel

Total Points: 67
Total Questions: 96
Total Answers: 119

Location: Marshall Islands
Member since Tue, Sep 21, 2021
3 Years ago
;