• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

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

 
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Java Cowboy
Posts: 16084
88
Android Scala IntelliJ IDE Spring Java
  • Likes 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Sheriff
Posts: 22781
131
Eclipse IDE Spring VI Editor Chrome Java Windows
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Ranch Hand
Posts: 144
Oracle Fedora Java
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Posts: 16084
88
Android Scala IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
WARNING! Do not activate jet boots indoors or you will see a tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic