Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Losing Info after an &...

 
Rich Barry
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 3244
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Rich Barry
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thx man.. that is a great idea...
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 65118
89
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Rich Barry
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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>
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic