Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

how to pass a parameter in the query string with the '+' sign in it unchanged.  RSS feed

 
neha agrawal
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
When a string containing a �+� is passed as a parameter in the URL in the query string through a GET request, it is interpreted as two strings separated by a �+� and thus when the string is retrieved through a request.getParameter (),it returns the string with a space in place of the �+� sign.
eg:
String dblink = "/TCE/servlet/LoginServicename="+vSystemAccount.getAccountName()+"&password="+pw;
Here the parameter pw contains a '+' sign which when retrieved by a request.getParameter() returns the parameter with a space in place of the '+' sign.How can i prevent this??
 
Ulf Dittmer
Rancher
Posts: 42970
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello "search java"-

Welcome to JavaRanch.

On your way in you may have missed that JavaRanch has a policy on display names, and yours does not comply with it - please adjust it accordingly, which you can do right here. Thanks for your prompt attention to this matter.

Enjoy your time here.
 
Ulf Dittmer
Rancher
Posts: 42970
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
As to your question, you can't prevent that from happening if you pass parameters in URLs. You can use the java.net.URLDecoder.decode method to convert it back to what it used to be. And to make sure it is being properly converted to a URL in the first place (instead of relying on the browser to get it right), you should call java.net.URLEncoder.encode to begin with:
String dblink = URLEncoder.encode(...);
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!