Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

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

 
chandubcs
Ranch Hand
Posts: 47
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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!
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic