473,414 Members | 1,764 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,414 software developers and data experts.

how to retreive a & as a value from query string

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 12 '08 #1
11 5429
r035198x
13,262 8TB
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 12 '08 #2
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 12 '08 #3
r035198x
13,262 8TB
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 12 '08 #4
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 13 '08 #5
sukatoa
539 512MB
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 13 '08 #6
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

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 15 '08 #7
BigDaddyLH
1,216 Expert 1GB
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:

Expand|Select|Wrap|Line Numbers
  1. import java.io.UnsupportedEncodingException;
  2. import java.net.URLEncoder;
  3. import java.net.URLDecoder;
  4.  
  5. public class URLEncoderTest {
  6.     public static void main(String[] args) throws UnsupportedEncodingException {
  7.         String charset = "UTF-8";
  8.  
  9.         String text = "Sturm & Drang = Storm & Stress";
  10.         String encoded = URLEncoder.encode(text, charset);
  11.         String decoded = URLDecoder.decode(text, charset);
  12.         System.out.format("'%s' => '%s' => '%s'%n", text, encoded, decoded);
  13.     }
  14. }
Note that this takes care of not just '&', but other special characters as well, like white space and '='.
May 15 '08 #8
raknin
82
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 15 '08 #9
BigDaddyLH
1,216 Expert 1GB
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 15 '08 #10
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 18 '08 #11
BigDaddyLH
1,216 Expert 1GB
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/ap...RLDecoder.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:
Expand|Select|Wrap|Line Numbers
  1. 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:
Expand|Select|Wrap|Line Numbers
  1. String decodedText = URLDecoder.decode(text, "UTF-8");//excellent
This is the version I used in my example, above.

Hope this clears things up.
May 18 '08 #12

Sign in to post your reply or Sign up for a free account.

Similar topics

4
by: Luklrc | last post by:
Hi, I'm having to create a querysting with javascript. My problem is that javscript turns the "&" characher into "&" when it gets used as a querystring in the url EG: ...
12
by: ~~~ .NET Ed ~~~ | last post by:
Hi, I have a standalone XML file (with the appropriate xml document header) that works fine when I load it using XmlDocument. I can have child elements like this without problems: ...
2
by: sam | last post by:
What is the quickest way to retreive total space and free space for the network drivers. Sam
0
by: ward | last post by:
Greetings. Ok, I admit it, I bit off a bit more than I can chew. I need to complete this "Generate Report" page for my employer and I'm a little over my head. I could use some additional...
3
by: Goran Djuranovic | last post by:
Hi All, Does anyone know how to retreive deepest XPath value from XML document by using VB.NET? For example, if I had an XML file like this: <Root> <Customer> <Name>MyName</Name> </Customer>...
1
by: JNariss | last post by:
Hello, I have created a connection to my Access database with Dreamweaver and made a simple form with 4 fields. The code behind this form was/is: <%@LANGUAGE="VBCRIPT" CODEPAGE="1252"%>...
0
by: gunimpi | last post by:
http://www.vbforums.com/showthread.php?p=2745431#post2745431 ******************************************************** VB6 OR VBA & Webbrowser DOM Tiny $50 Mini Project Programmer help wanted...
9
by: M | last post by:
Hello all, We've got the following problem: When a visitor klicks a dead link he ends up on a 404-page like should be. On that page there's an opportunity to mail the webmaster (me) about the...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.