Meaningless Drivel is fun!*
The moose likes Servlets and the fly likes Why is request.getParameterValues not working for me? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Java » Servlets
Bookmark "Why is request.getParameterValues not working for me?" Watch "Why is request.getParameterValues not working for me?" New topic
Author

Why is request.getParameterValues not working for me?

Jehan Jaleel
Ranch Hand

Joined: Apr 30, 2002
Posts: 196
Hi all,
I have a bunch of checkboxes in my JSP and I am just trying to get their values in my servlet.

Here is the JSP code snippet (extra HTML has been removed)....



Here is the code in the servelt...

String[] fileIds = request.getParameterValues("deleteFlag");

For some reason fileIds is null.

Any help would be much appreciated.

Thanks,
Jehan
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61310
    
  66

Are the checkboxes within the form being submitted? Are any of them checked?


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Lin Hung Ju
Greenhorn

Joined: Dec 05, 2008
Posts: 3
You can get the values of checkboxs
only when they are checked.
Jehan Jaleel
Ranch Hand

Joined: Apr 30, 2002
Posts: 196
Yes and yes. In fact when I use request.getParameter it does get the value of the first checkbox.

Any other suggestions?
Srikanth Nutigattu
Ranch Hand

Joined: Oct 30, 2007
Posts: 114
I think you have misspelt the name of the checkbox or something else. Since, you will get the values of all the checkboxes("That were selected")

The below code is working fine..



If you still can't find what is the problem in you code, copy-paste your code so that others can point out the problems..

HTH
Mr.David Shapiro
Ranch Hand

Joined: Apr 18, 2005
Posts: 51
I have the same thing happening. My case is a little more complicated. I am using innterHTML to create a table that has in the first column (i.e., <td>) an input of checkbox type. I click on submit and the table is generated along with the colum with the checkbox with id="reset". I can put in the input something like: <input type="checkbox" id="reset" onclick="resetvalue(this.value) value="something"> and if I click on the checkbox, it does go to the function I made and show the value that I put in an alert for test purposes. However, String[] reset = getParameterValues("reset") is null if I click on submit again. Any help wuold be appreciated.

Joe Sondow
Ranch Hand

Joined: Apr 10, 2005
Posts: 195
Mr.David Shapiro wrote:I have the same thing happening. My case is a little more complicated. I am using innterHTML to create a table that has in the first column (i.e., <td>) an input of checkbox type. I click on submit and the table is generated along with the colum with the checkbox with id="reset". I can put in the input something like: <input type="checkbox" id="reset" onclick="resetvalue(this.value) value="something"> and if I click on the checkbox, it does go to the function I made and show the value that I put in an alert for test purposes. However, String[] reset = getParameterValues("reset") is null if I click on submit again. Any help wuold be appreciated.



David,

Try changing id="reset" to name="reset".

Cheers,
Joe Sondow


SCJA 1.0 (98%), SCJP 1.4 (98%)
Mr.David Shapiro
Ranch Hand

Joined: Apr 18, 2005
Posts: 51
Thanks, I changed id to name. I think the magic fix was that I moved the code that generates the <div>targetDiv</div> that receives the table inside the <form> . This caused some issue because the form had some css style to it that got applied t the code in the targetDiv that I did not want, but I worked those out. It looks like I am back in business!

Kerry Wilson
Ranch Hand

Joined: Oct 29, 2003
Posts: 254
Mr.David Shapiro wrote:Thanks, I changed id to name. I think the magic fix was that I moved the code that generates the <div>targetDiv</div> that receives the table inside the <form> . This caused some issue because the form had some css style to it that got applied t the code in the targetDiv that I did not want, but I worked those out. It looks like I am back in business!



I think the magic fix was changing 'id' to 'name'. In any case, congrats on solving your problem!


http://www.goodercode.com
SCJP 1.4
 
GeeCON Prague 2014
 
subject: Why is request.getParameterValues not working for me?