Need JSP / JSTL Checkbox example

tmonteit used Ask the Experts™
I have a web page where a person is registering for a class.    In order to register, they need to click a 'checkbox' to indicate they agree with course policies.

I'm using struts and JSTL.

When the person hits submit, I can get other registration data into the Servlet text box.

example:   <nested:text property="userName"/>
I can get read the username property in my Servlet.

However, I'm confused about the checkbox.  How do I add a checkbox to the web page? and then read the content in the Servlet?

How do I know if the checkbox is clicked or not?  Is it a boolean?

Can someone provide a simple example?
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®

You can use <html:checkbox> to do that such as
<html:checkbox property="policies">Policies</html:checkbox>

Then you definitely need "policies" in your FormBean. I believe that it should return boolean. Give it a shot and see whether I am correct or not :)



I can't get it to work with either a String or Boolean 'policies'.  In all cases, the value is null when it gets to my servlet. ???

I'm scrubbing the web for a simple recipie.  put X in your jsp.  put Y in your FormBean.  Put Z in your servlet example.
How do you retrieve the FormBean?

Can you show me your JSP and Action?
Senior Web Developer
Boolean is object and you should use primitive boolean type.

in JSP:
<html:checkbox property="manager">Manager</html:checkbox>
<html:checkbox property="employee">Employee</html:checkbox>

in your formBean:
private boolean employee;
private boolean manager;

public boolean isEmployee() {
      return employee;
public boolean isManager() {
      return manager;
public void setEmployee(boolean b) {
      employee = b;
public void setManager(boolean b) {
      manager = b;

in ActionServlet:
protected void performAction(
  ActionMapping mapping,
  ActionForm form,
  HttpServletRequest request,
  HttpServletResponse response,
  ActionErrors errors,
  ActionForward forward)
  throws Exception {

      yourFormBean testForm = (yourFormBean) form;
      if (testForm == null)
            System.out.println("Form is null");                  
            System.out.println("==> Manager: " + testForm.isManager());
            System.out.println("==> Employee: " + testForm.isEmployee());

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial