Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

How to get address bar's text?

Posted on 2004-03-28
11
Medium Priority
?
326 Views
Last Modified: 2008-02-01
I use WebSphere 5.0 and I want to get address bar's text.
For example my addressbar is "http://locahost:9080/TestProject/welcome.do?par=2", how to get this text?

Thanks in advance.
0
Comment
Question by:thungrac01
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 3
  • 2
11 Comments
 
LVL 92

Accepted Solution

by:
objects earned 100 total points
ID: 10700790
request.getRequestURI()+request.getQueryString();
0
 
LVL 28

Assisted Solution

by:rrz
rrz earned 100 total points
ID: 10701062
The following works on Tomcat 5.  
<%=request.getRequestURL().toString() + "?" + request.getQueryString()%>  

objects, does your line really work ?
0
 
LVL 92

Expert Comment

by:objects
ID: 10701160
> does your line really work ?

Basically the same as what you posted, I just forgot the ?
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 7

Expert Comment

by:searlas
ID: 10702351
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.
0
 
LVL 28

Expert Comment

by:rrz
ID: 10704738
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.  
0
 
LVL 7

Expert Comment

by:searlas
ID: 10711962
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.
0
 
LVL 7

Expert Comment

by:searlas
ID: 10713501
rrz,  took me a while to remember what causes the getRequestURI/L to change without the browser knowing about it:

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

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






0
 
LVL 28

Expert Comment

by:rrz
ID: 10717406
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
0
 
LVL 7

Expert Comment

by:searlas
ID: 10722173
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?
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Whoever said that “a picture is worth one thousand words” observed a fact that can dramatically affect your marketing success. Most people tend to learn visually, so many publishers commonly acknowledge the effectiveness of visual learning by using…
When trying to connect from SSMS v17.x to a SQL Server Integration Services 2016 instance or previous version, you get the error “Connecting to the Integration Services service on the computer failed with the following error: 'The specified service …
This tutorial will teach you the special effect of super speed similar to the fictional character Wally West aka "The Flash" After Shake : http://www.videocopilot.net/presets/after_shake/ All lightning effects with instructions : http://www.mediaf…
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…

721 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question