aspose file tools*
The moose likes Beginning Java and the fly likes problem wih + symbol when concatenated with a string and ued in querystring. Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "problem wih + symbol when concatenated with a string and ued in querystring. " Watch "problem wih + symbol when concatenated with a string and ued in querystring. " New topic
Author

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

asma khanammd
Greenhorn

Joined: Jun 01, 2011
Posts: 3
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

Joined: Aug 16, 2005
Posts: 14144
    
  18

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.


Java Beginners FAQ - JavaRanch SCJP FAQ - The Java Tutorial - Java SE 7 API documentation
Scala Notes - My blog about Scala
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19693
    
  20

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.


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
Mike Zal
Ranch Hand

Joined: May 04, 2011
Posts: 144

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)


OCJP6, OCWCD5
Jesper de Jong
Java Cowboy
Saloon Keeper

Joined: Aug 16, 2005
Posts: 14144
    
  18

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
 
subject: problem wih + symbol when concatenated with a string and ued in querystring.