File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

problem wih + symbol when concatenated with a string and ued in querystring.

 
asma khanammd
Greenhorn
Posts: 3
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hai All,
I have a query string with the jsp. where i need to pass parameters to another jsp. when i am passing the parameters are getting passed correctly.

"getformattednumber.jsp?number=9876521430&pattern=[1-9][0-9]{9}&startindex=1&endindex=10&suffix=&prefix=+91" but when i am using

request.getParameter for variable prefix. it is taking only 91. "+" symbol is not getting. "+" symbol is replaced with space. How to resolve this issue.

thanks in advance.for time being am using temporary solution by passing "@@" in place of "+" . and am replacing in jsp. but this is not the exact solution.
Here from one jsp using javascript function, i am sending to another jsp. from this javascript function values are sent perfectly. but on the other side when i am using request.getParamter i am getting this problem.
 
Jesper de Jong
Java Cowboy
Saloon Keeper
Pie
Posts: 15150
31
Android IntelliJ IDE Java Scala Spring
  • 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Certain characters, such as the +, have special meanings in URLs, which means you cannot put them literally in URLs. You have to encode the URL in your Java program, and Java provides a class to do this (java.net.URLEncoder):

This will escape special character such as + with escape codes. You can use the encoded URL to access a server like you would do it with a "normal" URL.
 
Rob Spoor
Sheriff
Pie
Posts: 20380
46
Chrome Eclipse IDE Java Windows
  • 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Jesper, you shouldn't encode the entire part. The ? and = characters should remain as they are. Instead, encode only the keys and values:
Because I'm lazy I didn't encode everything, only those parts that need encoding. If the keys and values are more dynamic you should encode them all.
 
Mike Zal
Ranch Hand
Posts: 144
Fedora Java Oracle
  • 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Since you are using JSP, you should use the JSTL. Using the url tag will make things easier to write and will do rewriting and parameter encoding.

JSTL primer part 1
Part 2 (contains the url and param examples)
 
Jesper de Jong
Java Cowboy
Saloon Keeper
Pie
Posts: 15150
31
Android IntelliJ IDE Java Scala Spring
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Rob Spoor wrote:Jesper, you shouldn't encode the entire part. The ? and = characters should remain as they are.

Yes, you are right ofcourse, otherwise those will also get escaped and that's not what you want, because they have to be interpreted with their special meanings, instead of literally passed through.
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic