File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
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


Win a copy of Soft Skills this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Java » JSP
Bookmark "Losing Info after an &..." Watch "Losing Info after an &..." New topic
Author

Losing Info after an &...

Rich Barry
Greenhorn

Joined: Jan 28, 2002
Posts: 19
Hi...
Wnen I am passing information.... like this....
http://127.0.0.1:8080/forumoracle/forum_login.jsp?refurl=http://127.0.0.1:8080/forumoracle/forum_view.jsp?catid=2&threadid=4
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...
http://127.0.0.1:8080/forumoracle/forum_view.jsp?catid=2
Dave Vick
Ranch Hand

Joined: May 10, 2001
Posts: 3244
Rich
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


Dave
Rich Barry
Greenhorn

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

Joined: Jan 10, 2002
Posts: 61747
    
  67

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.
hth,
bear


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Rich Barry
Greenhorn

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: http://aspose.com/file-tools
 
subject: Losing Info after an &...