Solved

Need JSP / JSTL Checkbox example

Posted on 2006-10-19
5
7,534 Views
Last Modified: 2013-11-24
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?
0
Comment
Question by:tmonteit
5 Comments
 
LVL 16

Expert Comment

by:suprapto45
ID: 17770901
Hi,

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 :)
0
 

Author Comment

by:tmonteit
ID: 17771736

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.
0
 
LVL 16

Expert Comment

by:suprapto45
ID: 17771814
How do you retrieve the FormBean?

Can you show me your JSP and Action?
0
 
LVL 9

Accepted Solution

by:
owenli27 earned 300 total points
ID: 17773481
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");                  
      else{
            System.out.println("==> Manager: " + testForm.isManager());
            System.out.println("==> Employee: " + testForm.isEmployee());
      }
0
 
LVL 10

Assisted Solution

by:jaggernat
jaggernat earned 200 total points
ID: 17775738
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
squareUp  challenge 22 128
groovy example issue 10 87
eclipse java  build path 6 43
why cannot we forward request once the response is committed 2 33
Introduction This article is the first of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article explains our test automation goals. Then rationale is given for the tools we use to a…
Introduction This article is the last of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers our test design approach and then goes through a simple test case example, how …
The viewer will learn how to implement Singleton Design Pattern in Java.
This tutorial covers a practical example of lazy loading technique and early loading technique in a Singleton Design Pattern.

943 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

4 Experts available now in Live!

Get 1:1 Help Now