Alright I'll give that a shot, I really appreciate your help. As a little side question/comment... is that the only way to go about retrieving a boolean value from a form prior to JDK 1.5? That seems like a lot of overhead for what seems to me like a simple operation!
Originally posted by Jason Kwok: Hi, I have a form with a checkbox that indicates whether a category should be active or not. The form posts to my servlet, and I'm having trouble getting the boolean result from the form.
in my servlet, I have included java.lang.*; which includes the Boolean methods.
This is the LOC I have to read in the value from the checkbox:
I get this error: cannot resolve symbol symbol : method parseBoolean (java.lang.String) location: class java.lang.Boolean Boolean active = Boolean.parseBoolean(request.getParameter("active"));
What have I done wrong here?? Thanks to all who reply!
I have a couple of comments. First you don't need to import java.lang.*. The classes in this package are automagically imported for you, so you can use Boolean at will without importing it explicitly.
Second, I think you are making this more difficult than you need to. Perhaps this is partly because I don't have enough information here. You say that you are using a checkbox. Do you mean the Checkbox class from AWT or the JCheckbox class from Swing or some other class? If you are using Checkbox, then you can use the getState() method or if you are using JCheckbox, you can use the isSelected() method. Both of these return a primitive boolean directly without using the Boolean wrapper class.
Of course, I may be way off here. It will help clarify things if you show us the declaration for the request variable.
1. This question is more appropriate in the JSP forum
2. Be aware that for HTML checkboxes, no parameter will be submitted with the request if the checkbox is not checked. That means that you really only need to check for the presence of the parameter to see if the checkbox was checked; it really does not even matter what the value was at this point. If you do need to check the value, using equals() will do the trick.