how to retreive a & as a value from query string
Question posted by: prisesh26
(Newbie)
on
May 12th, 2008 07:16 AM
hi,
iam passing a name "sun & moon" in my query string as a parameter.
but when i receive it through request.getParameter iam getting only sun.
rest are getting ignored due to & symbol.
how to get the value as wat i entered through query string.
encoding with another symbol is not adviced. so can any one give a good solution
please help me
soon as possible .
Would you like to answer this question?
Sign up for a free account, or Login (if you're already a member).
|
|
May 12th, 2008 07:34 AM
# 2
|
Re: how to retreive a & as a value from query string
Quote:
Originally Posted by prisesh26
hi,
iam passing a name "sun & moon" in my query string as a parameter.
but when i receive it through request.getParameter iam getting only sun.
rest are getting ignored due to & symbol.
how to get the value as wat i entered through query string.
encoding with another symbol is not adviced. so can any one give a good solution
please help me
soon as possible .
|
Post the code where you are passing the parameter.
|
|
May 12th, 2008 07:40 AM
# 3
|
Re: how to retreive a & as a value from query string
thanks,
but iam fetching the name in one action class through request.getparameter and appending with other values with querystring and passing to second action class. when i get in second action class iam not getting the whole string.
|
|
May 12th, 2008 09:22 AM
# 4
|
Re: how to retreive a & as a value from query string
Quote:
Originally Posted by prisesh26
thanks,
but iam fetching the name in one action class through request.getparameter and appending with other values with querystring and passing to second action class. when i get in second action class iam not getting the whole string.
|
Read my reply above again.
|
|
May 13th, 2008 04:46 AM
# 5
|
Re: how to retreive a & as a value from query string
sorry,
iam new to java . i dont no how to pass the code by POST.
can you help me please.
from jsp iam doing POST to one class. but from that class i dont no how to post the query string by post when i pass through response.sendredirect.
to another class
|
|
May 13th, 2008 08:31 AM
# 6
|
Re: how to retreive a & as a value from query string
Quote:
Originally Posted by prisesh26
sorry,
iam new to java . i dont no how to pass the code by POST.
can you help me please.
from jsp iam doing POST to one class. but from that class i dont no how to post the query string by post when i pass through response.sendredirect.
to another class
|
Copy the piece of code where you are passing the parameter, paste it here.
regards,
sukatoa
|
|
May 15th, 2008 01:44 PM
# 7
|
Re: how to retreive a & as a value from query string
Hello frnd
I think you'll pass the parameter on href. Will you use this type? For example 'http://bytes.com/forum/newreply.php?do=newreply'&'p=3163121' see the site name. & symbol using middle of the two variable. So you can't retrieve it.
Use replace statement. For example
String ss = "str&str1";
ss = ss.replace('&','xxxxx');
Try this method
GoodLuck
Quote:
Originally Posted by prisesh26
hi,
iam passing a name "sun & moon" in my query string as a parameter.
but when i receive it through request.getParameter iam getting only sun.
rest are getting ignored due to & symbol.
how to get the value as wat i entered through query string.
encoding with another symbol is not adviced. so can any one give a good solution
please help me
soon as possible .
|
|
|
May 15th, 2008 04:29 PM
# 8
|
Re: how to retreive a & as a value from query string
Quote:
Originally Posted by nanaveraa
Hello frnd
I think you'll pass the parameter on href. Will you use this type? For example 'http://bytes.com/forum/newreply.php?do=newreply'&'p=3163121' see the site name. & symbol using middle of the two variable. So you can't retrieve it.
Use replace statement. For example
String ss = "str&str1";
ss = ss.replace('&','xxxxx');
Try this method
GoodLuck
|
What if xxxxx is part of the original string? A much better solution is to use the API:
Code: ( text )
import java.io.UnsupportedEncodingException; import java.net.URLEncoder; import java.net.URLDecoder; public class URLEncoderTest { public static void main(String[] args) throws UnsupportedEncodingException { String charset = "UTF-8"; String text = "Sturm & Drang = Storm & Stress"; String encoded = URLEncoder.encode(text, charset); String decoded = URLDecoder.decode(text, charset); System.out.format("'%s' => '%s' => '%s'%n", text, encoded, decoded); } }
Note that this takes care of not just '&', but other special characters as well, like white space and '='.
|
|
May 15th, 2008 07:19 PM
# 9
|
Re: how to retreive a & as a value from query string
I had this problem a few days ago and I solve it as following:
Before you send the your request to the server replace all the "&" with some string that you decide about and doesn't appear in the your parameter e.g DUMMY it. on the server just replace the string you relace previously in the client side with the & again. I hope this will help
|
|
May 15th, 2008 08:40 PM
# 10
|
Re: how to retreive a & as a value from query string
Quote:
Originally Posted by raknin
I had this problem a few days ago and I solve it as following:
Before you send the your request to the server replace all the "&" with some string that you decide about and doesn't appear in the your parameter e.g DUMMY it. on the server just replace the string you relace previously in the client side with the & again. I hope this will help
|
I still think using the HHTP standard and java's standard API, namely URLEncoder/URLDecoder, is the way to go.
|
|
May 18th, 2008 07:57 AM
# 11
|
Re: how to retreive a & as a value from query string
hi guys,
i tried with urlDECODER but its a depricated class so we cannot use that.
i tried by replacing the & with %26 and i passed to query string.
in request parameter %26 is escaped with & value.
so iam getting the value properly
now its working fine.
thanks dudes.
:)
|
|
May 18th, 2008 06:08 PM
# 12
|
Re: how to retreive a & as a value from query string
Quote:
Originally Posted by prisesh26
hi guys,
i tried with urlDECODER but its a depricated class so we cannot use that.
i tried by replacing the & with %26 and i passed to query string.
in request parameter %26 is escaped with & value.
so iam getting the value properly
now its working fine.
thanks dudes.
:)
|
You are misreading: java.net.URLDecoder is not a deprecated class, at least not as of 1.6:
http://java.sun.com/javase/6/docs/a...URLDecoder.html
If you take the time to read the API documentation, you'll see that what is deprecated is the version of the decode method that takes one string:
Code: ( text )
String decodedText = URLDecoder.decode(text);//deprecated
Like almost all deprecated parts of the API, there are instructions what to do instead. In this, you should use the other version of decode, which takes the name of a charset encoding:
Code: ( text )
String decodedText = URLDecoder.decode(text, "UTF-8");//excellent
This is the version I used in my example, above.
Hope this clears things up.
 |
Not the answer you were looking for? Post your question . . .
174,848 Experts ready to help you find a solution.
Sign up for a free account, or Login (if you're already a member).
|
|
|
Top Java Forum Contributors
|