This week's giveaway is in the Threads forum.
We're giving away four copies of Java Concurrency Live Lessons and have Doug Schmidt on-line!
See this thread for details.
Win a copy of Java Concurrency Live Lessons this week in the Threads forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Problem in passing request parameter  RSS feed

 
Manoj Gundawar
Ranch Hand
Posts: 169
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
I need to pass few parameters to JSP at request time follows:

http://localhost:9080/temp/dmgjsp/authenticate.jsp?userid=gundawam&upassword=zS3KQ+3CoA7KwI5Lrb7VMA==

But when I do request.getParameter(upassword), inside authenticate.jsp, it
gives the value "zS3KQ 3CoA7KwI5Lrb7VMA==" and not the real value "zS3KQ+3CoA7KwI5Lrb7VMA==".
Note that "+" is replaced by " " (space)
And as this is an encrypted password, it fails in further processing.

Is there any indepth information about how to pass request parameter as query string and what are the limitations and workaround?

Any help in this regard is appriciated.

Thanks,
Manoj
[ September 23, 2004: Message edited by: Jmannu gundawar ]
 
Dirk Schreckmann
Sheriff
Posts: 7023
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you are going to hard code get request parameters, then they need to be escaped properly. Off hand, I don't know of a web site that lists all of the characters that need escaping, along with their escape character sequences.

Using the following demo JSP, I was able to quickly figure out that the character '+' is "%2B" when coming in as part of a request parameter.
[ September 24, 2004: Message edited by: Dirk Schreckmann ]
 
Manoj Gundawar
Ranch Hand
Posts: 169
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Dirk,
I am afraid, but I might have missed your point. I still have 2 questions:
1. As per your response, if I am hard coding the getParameter, I need to use proper escape sequence. What is other way of getting the request parameter besides hard coding, which will avoid this issue? I tried getParameterValues etc. All gives the same problem. Except getQueryString. But I don�t want to use this, as I need to parse the string to know what are values of each param.

2. I tried the sample JSP you have used. This also shows "+" as " " (space)
How did you figure out (using this JSP) that %2B stands for + (which is correct)

Please let me know.

Thanks,
Manoj
[ September 27, 2004: Message edited by: Jmannu gundawar ]
 
Kamlesh Sangani
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
did u try
?
 
Manoj Gundawar
Ranch Hand
Posts: 169
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Kamalesh,

But this only escapes characters that could be interpreted as XML markup.
It does not solve my problem forever as, the query string is the encoded passoword which could have any charachter.
I also tried following, but none of these worked. (I am using WSAD 5.1)


1. I did set the request's char encoding before getting any param.
request.setCharacterEncoding("UTF-8");
2. Set pageEncoding,contentType (charset ) to UTF-8 for the page receiving this parameter.

3. Tried forcing the conversion as follows:
String myparam = request.getParameter("parameter");

String n = new String(
myparam.getBytes( "ISO-8859-1" ),
"UTF-8"
);

But none of the above worked to get "+" as it is from request string. (gave " " (space) instead)

Any help is highly appriciated.

Thanks,
Manoj
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!