Chris/Thomas,
Yes, it is a server-side java, servlet type (actually, it's a Cocoon 2.0.4
application with sitemap actions,
but I didn't want to scare anybody off), JRE 1.4.2.
[color=blue]
> ...page2?v2=first,second,third[/color]
Yes, if I call getParameterValues(v2) with
window.location.href="page2?v2=" + getCheckedValues(v1);
in the URL I see: ...page2?v2=123,456,789...&<other params>
The problem is that I can't get that value "123,456,789.." in Java (get one
empty string).
Do you know how to do that ?
I thought that Javascript array disappears after page1 is replaced by page2
in the browser.
That's why I try to create a hidden input v2 on page1 to store the array of
checked checkbox values.
Is that necessary ?
I have no problems parsing that string and creating String array out of it.
[color=blue]
> But you really ought to also take Thomas's advice, and use a proper HTML
> form instead of your JavaScript-with-URL-building hack. This would have
> saved you a lot of confusion, since there are plenty of tutorials on how
> to read HTML form content from servlets.[/color]
Please elaborate on "use a proper HTML form".
As I mentioned, I am trying to pass that Javascript array (or set of
checkboxes)
from one page (form) to another.
If there a better way of doing it, please give more details.
[color=blue][color=green]
>>I do not think this is necessary or desirable. Use a `form' element
>>(with `action' attribute omitted or set to "GET") instead, and let
>>the UA compose the query-part.[/color][/color]
What does "let the UA compose the query part" mean ? Please elaborate.
Both web pages are in XSLT and there are other reasons why I call page2 via
URL "onclick" event.
Do not want to put a lot of less relevant info here.
Thank you in advance,
Oleg.
"Chris Smith" <cdsmith@twu.net> wrote in message
news:MPG.1df820e2531dd759989bb0@news.altopia.net.. .
[color=blue][color=green]
>> Oleg Konovalov wrote:[color=darkred]
>> > In the Java class attached to page2[/color][/color]
>[color=green][color=darkred]
>> > I try to do:
>> > String [] ids = request.getParameterValues("v2");[/color][/color]
>
> and later...
>[color=green][color=darkred]
>> > <input type="hidden" name="v2"/>
>> > in "onclick" event of page1 I execute JavaScript"
>> >
>> > if (this.v1) v2.value=getCheckedValues(v1);
>> > window.location.href="page2?v2=" + v2.value;[/color][/color]
>
> You're submitting only ONE form parameter, with a name of v2 and a value
> of whatever getCheckedValues returns. Although it would have been nice
> if you provided the code to getCheckedValues, there is one thing I can
> definitely tell you. You don't want to be calling getParameterValues in
> the servlet.
>
> The getParameterValues method is intended to be used where there is
> potentially more than one value for the same name. That is, if (using
> HTTP GET) your URL looked something like:
>
> ...page2?v2=first&v2=second&v2=third
>
> That isn't what you're doing, though. Based on what you wrote, it
> sounds like you're doing this instead:
>
> ...page2?v2=first,second,third
>
> That is providing only ONE parameter, with a name of "v2" and a value of
> "first,second,third". If you call getParameterValues, it will work
> fine, but it will return an array of length one, and the only element
> will be the String "first,second,third".
>
> If you want to keep that URL format, you need to modify your servlet
> code to parse the parameter. Something like this:
>
> String paramValue = request.getParameter("v2");
> String[] ids = paramValue.split(Pattern.quote(","));
>
> (If using a Java version prior to 1.5, Pattern.quote won't be available.
> In that case, replace Pattern.quote(",") with "\\," comma. Even the
> backslash there is not strictly necessary, but that is good form since
> commas are reserved Java regexp syntax in at least some situations. If
> your Java version is prior to 1.4, though, then you'll need to use
> StringTokenizer instead of the newer String.split in the first place.)
>
> But you really ought to also take Thomas's advice, and use a proper HTML
> form instead of your JavaScript-with-URL-building hack. This would have
> saved you a lot of confusion, since there are plenty of tutorials on how
> to read HTML form content from servlets.
>
> --
>
www.designacourse.com
> The Easiest Way To Train Anyone... Anywhere.
>
> Chris Smith - Lead Software Developer/Technical Trainer
> MindIQ Corporation[/color]