• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Losing Info after an &...

 
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Ranch Hand
Posts: 3244
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thx man.. that is a great idea...
 
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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>
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic