File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Servlets and the fly likes req.getParameterValues returning null Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCA/OCP Java SE 7 Programmer I & II Study Guide this week in the OCPJP forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "req.getParameterValues returning null" Watch "req.getParameterValues returning null" New topic
Author

req.getParameterValues returning null

Chak Terlapu
Ranch Hand

Joined: Oct 20, 2000
Posts: 32
Hi,
I am using a servlet to display a table, and i am assigning a check box to each table row as follows:

the table has a "delete" button at the bottom. When the user clicks on some check boxes and clicks the delete button the rows should be deleted. I am trying to capture the checkbox events as follows:

The problem is when i click on some check boxes and click "delete" button a null value is returned for all the checkboxes.
it would be great if anyone could help me.
thanks
jason adam
Chicken Farmer ()
Ranch Hand

Joined: May 08, 2001
Posts: 1932
Have you thought about taking <FORM> out of the while loop, put it before, and close it with </FORM> after the loop finishes?
[This message has been edited by jason adam (edited August 22, 2001).]
k b
Greenhorn

Joined: Feb 01, 2001
Posts: 22
req.getParameterValues will return null if no such parameter name found in the request, so you should check the name of check boxes by doing view source in your browser and try to check their names more closely.
Secondly you will only get checkboxes those are marked, un-marked check boxes are not sent with the request ( for those names you will get null).
Hope this help.
k b
Chak Terlapu
Ranch Hand

Joined: Oct 20, 2000
Posts: 32
Hi,
I tried it but with no luck. I cant understand where the problem is.
I checked in the view source the name of the checkboxes, everything is fine, the name ranges from icheck[0], icheck[1] ..icheck[58].
I am getting null value for also the checkboxes that are marked.
Thanks
Manjunath Reddy
Ranch Hand

Joined: Jul 26, 2001
Posts: 60
There sure is some flaw with ur processing the request. Below is a sample code that i wrote for testing. Maybe that will help
Page: checkbox.jsp
<pre>
<%@ page import='java.util.*'%>
<html>
<head><title>Check Box Test Page</title></head>
<body bgcolor=#ffffff>
<FORM action="/checkboxresults.jsp">
<%
int i=0;
while(i<10)
{
out.println("<TD align=center><input type=checkbox name=icheck["+(i++)+"] value=yes></TD>");
}
%>
<input type = submit name=submit value=GO!>
</FORM>
</body>
</html>
</pre>

Page: checkboxresults.jsp
<pre>
<%@ page import='java.util.*'%>
<html>
<head><title>Check Box Test Page</title></head>
<body bgcolor=#ffffff>
<%
Hashtable ht = new Hashtable();
Enumeration e = request.getParameterNames();
while (e.hasMoreElements())
{
String name = (String) e.nextElement();
String[] values=request.getParameterValues(name);
if( values.length > 1) {
ht.put( name, values );
}
else
{
ht.put( name, request.getParameter( name ) );
}
}

out.println(ht.toString());
%>
</body>
</html>
</pre>
chz.
mpr
[This message has been edited by Manjunath Reddy (edited August 22, 2001).]
Manjunath Reddy
Ranch Hand

Joined: Jul 26, 2001
Posts: 60

Sorry though for the wasted forum space..since i had a function which converts a request to hashtable..i just used that to demonstrate that ur pages work...
Chak Terlapu
Ranch Hand

Joined: Oct 20, 2000
Posts: 32
Hi,
Thanks for the response. I tried your way but no luck. Can anyone help me correct my approach.
Thanks
Manjunath Reddy
Ranch Hand

Joined: Jul 26, 2001
Posts: 60
With the above code...i could get the names of the checkboxes that i had selected..isnt that what you want..?
Chak Terlapu
Ranch Hand

Joined: Oct 20, 2000
Posts: 32
Hi,
Itss so strange the same thing is not working for me. It does not print anything in the log files.


and I am trying to retrieve it using:

Thanks
Manjunath Reddy
Ranch Hand

Joined: Jul 26, 2001
Posts: 60
In ur case you are submitting a value of "yes" whenever a check box is selected along with its name. Is that right?
Its not as difficult as we are trying to solve this...tell me what exactly u want see in ur log.
Name and values of checkboxes selected?
Chak Terlapu
Ranch Hand

Joined: Oct 20, 2000
Posts: 32
Hi,
I also tried in a different approach but without sucess:

[code]
//receiving parameters
cont.log("value of num: "+req.getParameter("number"));
int num1 = Integer.parseInt(req.getParameter("number"));
for(int i=0; i< num1; i++)
{
String ch = req.getParameter("icheck"+i);
cont.log("check: " +ch);
}

[code]
It is failing at req.getParameter("number"), which i cant understand as the "number" name exists.
Chak Terlapu
Ranch Hand

Joined: Oct 20, 2000
Posts: 32
Hi,
I am just trying to debug it by printing the output in the logs. I actually need to know the check box number (i.e. from icheck[10] the value of 10) which has been marked by the user, with the help of which i will be able to relate it to the rowid of the table row. The rowid's are all stored in an array, so if i can know the rowid i will be able to delete the marked row.
thanks
Manjunath Reddy
Ranch Hand

Joined: Jul 26, 2001
Posts: 60
In my src code that i previously posted here change the line that prints the checkboxes to
<pre>
out.println("<TD align=center><input type=checkbox name=icheck["+(i++)+"] value=check" + i + "></TD>");
</pre>
Now hit the checkbox.jsp and select a few checkboxes and click on GO...in the next page you will see the values as well as names. I guess the problem you are having is that each checkbox is posting a value "yes"...since its harcoded..
Hope this brings an end to this thread...

 
Don't get me started about those stupid light bulbs.
 
subject: req.getParameterValues returning null