aspose file tools*
The moose likes JSP and the fly likes how to manipulate ampersand(&) char in JSP query string Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » JSP
Bookmark "how to manipulate ampersand(&) char in JSP query string" Watch "how to manipulate ampersand(&) char in JSP query string" New topic
Author

how to manipulate ampersand(&) char in JSP query string

chandubcs
Ranch Hand

Joined: Jun 03, 2001
Posts: 47
Hi,
How to manipulate ampersand character in JSP's. I need to use '&' char in the URL string. For ex: "../test.jsp?id=1059&title=Test for RM&DRT". Here I can get id using request.getParameter("id") and same as title. But title I am getting as 'Test for RM', I am missing '&DRT. I know '&' seperates parameters, but I need to send 'Test for RM&DRT' as whole URL string. I tried '&' char with %26 char, its working fine if I hardcode it in browser. I want to send it from a JSP page to another JSP page. Could anyone please suggest me how to solve the problem.
thanks,
Andy Jenks
Greenhorn

Joined: Feb 13, 2002
Posts: 3
You need to use the UrlEncoder class to encode the parameter's value e.g.
String s = "ab&d defgh";
String paramvalue = URLEncoder.encode(s);
you can then pass this encoded value intact in the url and use
URLDecoder.decode to decode the value.
Hope this helps!
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: how to manipulate ampersand(&) char in JSP query string