File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes JSP and the fly likes Losing Info after an &... Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » JSP
Bookmark "Losing Info after an &..." Watch "Losing Info after an &..." New topic

Losing Info after an &...

Rich Barry

Joined: Jan 28, 2002
Posts: 19
Wnen I am passing information.... like this....
I seem to be losing the information after the amperstand.. and not sure why..
String url = request.getParameter("refurl");
So when I print out the url string.. I only get this...
Dave Vick
Ranch Hand

Joined: May 10, 2001
Posts: 3244
That's becaue the & is used to separate name value pairs in the query string. so when you ask for the parameter 'refurl' it thinks the end of that parameter is at the &.
If 'threadid' is always the next parameter name then you can just use:
String thread = request.getParameter("threadid");
to get the value of that parameter.
If it is different all the time you can use the getQueryString( ) method of the HttpServletRequest object and then parse it yourself.
hope that helps

Rich Barry

Joined: Jan 28, 2002
Posts: 19
Thx man.. that is a great idea...
Bear Bibeault
Author and ninkuma

Joined: Jan 10, 2002
Posts: 63838

What's producing the original URL? If you have control over that you can URL encode the value of the refurl parameter in the first place and not have to worry about parsing anomalies.

[Asking smart questions] [About Bear] [Books by Bear]
Rich Barry

Joined: Jan 28, 2002
Posts: 19
What I do.. is when the click on a link.. on the top of the page it checks to see if the are login or not.. if they are not.. I want to send them back to the original page... So I get set a variable of the page the are on.. and just pass it only through the login process...
So how do I use the URL encode??
// This gets the current url
String url = "";
String servername = request.getServerName();
int serverport = request.getServerPort();
String uri= request.getRequestURI();
String query = request.getQueryString();
url += "http://";
url += servername;
url += ":";
url += serverport;
url += uri;
url += "?";
url += query;
a href="forum_login.jsp?refurl=<%= url %>" class="mouseover">Login</a>
I agree. Here's the link:
subject: Losing Info after an &...
jQuery in Action, 3rd edition