That's not going to help too much. What you want to do is check for the parameter
value being null or not null -- if it isn't null, you got something back and can
evaluate the value. If it's null, handle it as though it were unchecked.
i.e.
boolean checkBoxIsChecked = req.getParameter("checkBoxParm") != null;
or, if you want to set it to a value:
String checkBoxValue = req.getParameter("checkBoxParm") ==
null?"someDefaultText":req.getParameter("checkBoxParm");
John Larson wrote:
> Thomas,
>
> The checkbox behavior is surprising, but normal.....
>
> You can use the following code to retrieve the values:
>
> String[] frmCourseKey = req.getParameterValues("check_box"); //This is
> the parm name
>
> for (int i = 0;i < frmCourseKey.length; i++)
> {
> String courseKey = frmCourseKey[i]
> Do the rest of your processing with the value......
> }
>
> Good luck,
> John
>
> Thomas To wrote:
> >
> > Hi all,
> >
> > I'm writing a servlet to get input values from an HTML form and put them
> > into the database. I use both input type="text" and input
> > type="checkbox". In the servlet makes call to
> > ServletRequest.getParameterNames() and ServletRequest.getParameter() to
> > retrieve all the parameters and their values. I realize that for all
> > text type, if nothing is put in, the parameter name will be return and
> > the value is an empty string. However, for checkbox type, if all
> > checkboxes are unchecked, getParameterNames() will not even return the
> > parameter name. Is this normal? Is there any way that
> > getParameterNames() will return the parameter name with empty string
> > like the text type?
> >
> > Can anyone give me some info on this?
> >
> > Thanks.
> >
> > - Thomas -
> >
> > ___________________________________________________________________________
> > To unsubscribe, send email to [EMAIL PROTECTED] and include in the body
> > of the message "signoff SERVLET-INTEREST".
> >
> > Archives: http://archives.java.sun.com/archives/servlet-interest.html
> > Resources: http://java.sun.com/products/servlet/external-resources.html
> > LISTSERV Help: http://www.lsoft.com/manuals/user/user.html
>
> ___________________________________________________________________________
> To unsubscribe, send email to [EMAIL PROTECTED] and include in the body
> of the message "signoff SERVLET-INTEREST".
>
> Archives: http://archives.java.sun.com/archives/servlet-interest.html
> Resources: http://java.sun.com/products/servlet/external-resources.html
> LISTSERV Help: http://www.lsoft.com/manuals/user/user.html
___________________________________________________________________________
To unsubscribe, send email to [EMAIL PROTECTED] and include in the body
of the message "signoff SERVLET-INTEREST".
Archives: http://archives.java.sun.com/archives/servlet-interest.html
Resources: http://java.sun.com/products/servlet/external-resources.html
LISTSERV Help: http://www.lsoft.com/manuals/user/user.html