473,508 Members | 2,195 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Passing valus through the url

Hi,
i am trying to pass values to a struts action using javascript. It
works fine until the value has something like '+' or '&' sign in it.
Is this a problem with javascript or these values cannot be passed in
the URL ?

takeExample.do?field='+field+'&Code='+code

this is the url im making

if code is 'trying + something else'
i get 'trying something else' from the request.getParameter

if it is 'trying & something else'
i get 'trying '
Please Help
Thnax in advance
Jul 23 '05 #1
1 1011
On 4 Jan 2005 20:26:25 -0800, sancha <ch**************@gmail.com> wrote:
i am trying to pass values to a struts action using javascript. It
works fine until the value has something like '+' or '&' sign in it. Is
this a problem with javascript or these values cannot be passed in the
URL ?
They must be escaped. The ampersand (&) is used to separate name/value
pairs, and plus (+) can be used (but it's not the only way) to replace
spaces. Call encodeURIComponent with the values you're going to add.
takeExample.do?field='+field+'&Code='+code


'takeExample.do?field='
+ encodeURIComponent(field) + '&Code='
+ encodeURIComponent(code)

Unfortunately, encodeURIComponent isn't implemented by older browsers.
However, you can emulate it:

if('function' != typeof encodeURIComponent) {
this.encodeURIComponent = function(uri) {
var x = /[\w.!~*'()-]/, r = '';
for(var c, i = 0, n = uri.length; i < n; ++i) {
if(x.test(c = uri.charAt(i))) {r += c;}
else {
c = uri.charCodeAt(i).toString(16).toUpperCase();
r += ((c.length == 1) ? '%0' : '%') + c;
}
}
return r;
};
}

The code above will determine whether the function is implemented by the
browser. If not, a basic implementation[1] will be created.

Mike
[1] By "basic implementation" I'm referring to the fact that
encodeURIComponent should be able to deal with Unicode characters. The
implementation above only concerns itself with the ISO-8859-1 (Latin)
character set.

--
Michael Winter
Replace ".invalid" with ".uk" to reply by e-mail.
Jul 23 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

15
4649
by: Dave | last post by:
I'm currently working on a small project (admitedly for my CS class) that compares the time difference between passing by value and passing by reference. I'm passing an array of 50000 int's. ...
58
10049
by: jr | last post by:
Sorry for this very dumb question, but I've clearly got a long way to go! Can someone please help me pass an array into a function. Here's a starting point. void TheMainFunc() { // Body of...
9
2289
by: Just Me | last post by:
PARAFORMAT2 is a structure that SendMessage will return stuff in. Is the "ref" correct or since only a pointer is being passed should it be by value? Suppose I was passing data rather then...
8
2106
by: Dennis Myrén | last post by:
I have these tiny classes, implementing an interface through which their method Render ( CosWriter writer ) ; is called. Given a specific context, there are potentially a lot of such objects,...
22
25548
by: Arne | last post by:
How do I pass a dataset to a webservices? I need to submit a shoppingcart from a pocket PC to a webservice. What is the right datatype? II have tried dataset as a datatype, but I can't get it to...
6
5979
by: MSDNAndi | last post by:
Hi, I get the following warning: "Possibly incorrect assignment to local 'oLockObject' which is the argument to a using or lock statement. The Dispose call or unlocking will happen on the...
12
2662
by: Andrew Bullock | last post by:
Hi, I have two classes, A and B, B takes an A as an argument in its constructor: A a1 = new A(); B b = new B(a1);
12
5367
by: Mike | last post by:
Consider the following code: """ struct person { char *name; int age; }; typedef struct person* StructType;
7
3290
by: TS | last post by:
I was under the assumption that if you pass an object as a param to a method and inside that method this object is changed, the object will stay changed when returned from the method because the...
4
2805
by: Deckarep | last post by:
Hello fellow C# programmers, This question is more about general practice and convention so here goes: I got into a discussion with a co-worker who insisted that as a general practice all...
0
7127
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
7331
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,...
1
7054
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
7501
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
5633
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,...
1
5056
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...
0
3204
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3188
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
424
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

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.