使用path属性将boolean值传递给控制器​​的jsp页面

时间:2021-06-01 11:53:21

I want to know how to set checkbox value from controller .Please find my code.

我想知道如何从控制器设置复选框值。请找到我的代码。

Controller:

......
......
Student student=service.findRecord(studentID) //received record from DAOImpl 
.....
.....
return "EditStudent";

Student.java

 @Entity
 @Table(name = "student_detail")
 public class Student
 {
 @Id 
 @Column(name = "ID")
 @GeneratedValue
 private int ID;
 @Column(name = "studentID")
 private int studentID;
 @Column(name = "studentDescrip")
 private String studentDescrip;
 @Column(name = "status")
 private boolean status;
 .....
 .....getter setter method

EditStudent.jsp

......
......
<tr class="hide convert">
<th>Status</th>
<td><form:checkbox name="Status" id="Status" 
path="student.Status" class="form-control" />
</td>
</tr>

My problem is checkbox status always set true.I am getting status value is false in controller, but it does not set status is false in jsp page. Please correct my code...

我的问题是复选框状态始终设置为true。我在控制器中获取状态值为false,但在jsp页面中未设置状态为false。请更正我的代码......

2 个解决方案

#1


1  

If you are using spring tags, you have to use this

如果您使用的是spring标签,则必须使用它

In your controller you have to add an object "student" to the ModelAndView

<form:form model="student">
   <td>
       <!-- Here you access to the status attribute, case sensitive.--> 
       <form:checkbox id="Status" path="status" class="form-control" />
   </td>
...
</form>

#2


0  

If you're using simple jsp page, then

如果你正在使用简单的jsp页面,那么

<tr class="hide convert">
    <th>Status</th>
    <td><form:checkbox name="Status" id="Status" 
    path="<%=student.Status %>" class="form-control" />
    </td>
</tr>

please note: you should write logic that will get student object before writing this code.

请注意:在编写此代码之前,您应该编写将获得student对象的逻辑。

#1


1  

If you are using spring tags, you have to use this

如果您使用的是spring标签,则必须使用它

In your controller you have to add an object "student" to the ModelAndView

<form:form model="student">
   <td>
       <!-- Here you access to the status attribute, case sensitive.--> 
       <form:checkbox id="Status" path="status" class="form-control" />
   </td>
...
</form>

#2


0  

If you're using simple jsp page, then

如果你正在使用简单的jsp页面,那么

<tr class="hide convert">
    <th>Status</th>
    <td><form:checkbox name="Status" id="Status" 
    path="<%=student.Status %>" class="form-control" />
    </td>
</tr>

please note: you should write logic that will get student object before writing this code.

请注意:在编写此代码之前,您应该编写将获得student对象的逻辑。