How to get address bar's text?

I use WebSphere 5.0 and I want to get address bar's text.
For example my addressbar is "http://locahost:9080/TestProject/", how to get this text?

Thanks in advance.
Who is Participating?

Improve company productivity with a Business Account.Sign Up

objectsConnect With a Mentor Commented:
rrzConnect With a Mentor Commented:
The following works on Tomcat 5.  
<%=request.getRequestURL().toString() + "?" + request.getQueryString()%>  

objects, does your line really work ?
> does your line really work ?

Basically the same as what you posted, I just forgot the ?
Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

I think there are cases where you really have to use JavaScript for this.  Sometimes
the app server redirects internally, changing the result of request.getRequestURI(), but
the browser will still display the original address it requested.
searlas, I am confused by your comment.
>Sometimes the app server redirects internally  
Are you referring to a <jsp:forward   ?    
In that case the request object remains the same.  
Actually... let's just forget that for a minute.  If you want the address bar text the only way to do this IS with javascript.
I give you... frames.
rrz,  took me a while to remember what causes the getRequestURI/L to change without the browser knowing about it:

<% request.getRequestDispatcher("two.jsp").forward(request, response); %>

URI: <%= request.getRequestURI() %><br/>
URL: <%= request.getRequestURL() %>

thungrac01 did not specify whether he was using a forward or not.
So, I hope we are not getting too far off topic here.  

searlas, I ran the code from your last post. Here are the results(in Tomcat 5).
Browser address bar: http://localhost:8080/one.jsp
URI: /two.jsp  
URL: http://localhost.8080/one.jsp   

I tried also with
<jsp:forward  page="two.jsp"/>  and with  
<% application.getRequestDispatcher("/two.jsp").forward(request, response); %>  
Using either of the three methods, results are the same.  

Of course without the forward we have  
Browser address bar: http://localhost:8080/one.jsp
URI: /one.jsp
URL: http://localhost:8080/one.jsp   

Now, if two.jsp forwards to three.jsp we have the result
Browser address bar: http://localhost:8080/one.jsp
URI: /three.jsp
URL: http://localhost:8080/one.jsp 

On page 95 of Jason Hunter's book "Java Servlet Programming" first edition 1998  
"For servlets in a chain, the request URI is always that of the first servlet in the chain."
But that is not the results I received.  
Please comment.    rrz
As you say, not wanting to get too offtopic...
thungrac01 does not specify any limitations on frames/forwards/includes etc, hence my comments wrt JavaScript to get the url as it appears in the browsers address bar.

I ran with WebLogic 6.1:
Browser address bar: http://localhost:8080/one.jsp
URI: /two.jsp  
URL: http://localhost.8080/two.jsp 

I get these results consisently for all methods of forwarding.  And, if two forwards to three I have:
URI: /three.jsp  
URL: http://localhost.8080/three.jsp 

Now, thungrac01 uses WebSphere 5.0, so... who knows?
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.