jsp 中如何将页面中 radio和checkbox 值 带到其他页面中

 一个简单的注册.jsp页面,不可能只有输入框,那样的话,用户体验将比较差,所以少不了一些控件了,比如radio 、checkbox 等等了,那这些控件选中值 怎么在多个页面传递呢???

 
 
1.类的设计
public class User implements Serializable{
 
private int id;
private String name;
private String password;
private String email;
private long birthday;
private int gender;
private int degree;
private String intrest;
private String introduction;
........
}
2.数据库设计
create table if not exists user(
id int primary key auto_increment,
name varchar(32) unique,
password varchar(32) not null,
email varchar(32),
birthday bigint,
gender int,
degree int,
intrest varchar(32),
introduction text
);
3、register 界面
 
jsp <wbr>中如何将页面中 <wbr>radio和checkbox <wbr>值 <wbr>带到其他页面中

就上面的register上的数据进行保存。同时在其他页面显示。比如用户信息查看页面 就这些信息进行复原。
 
4、编写代码(核心代码)
  <tr>
    <th>性别</th>
    <td>
     <input type="radio" id="mail" name="gender" checked="checked" value="1"/>男
     <input type="radio" id="femail" name="gender" value="2"/>女
    </td>
  </tr>
  <tr>
     <th>学历</th>
     <td>
     <input type="radio" id="dazhuan" name="degree" value="1"/>大专
     <input type="radio" id="benke" name="degree" value="2"/>本科
     <input type="radio" id="shuoshi" name="degree" value="3"/>硕士
     <input type="radio" id="boshi" name="degree" value="4"/>博士
     </td>
  </tr>
      <tr>
   <th>兴趣</th>
   <td>
   <input type="checkbox" id="film" name="intrest" value="1"/>电影
   <input type="checkbox" id="game" name="intrest" value="2"/>游戏
   <input type="checkbox" id="sport" name="intrest" value="3"/>运动
   <input type="checkbox" id="study" name="intrest" value="4"/>学习
   </td>
      </tr>
 在用户列表页面点击查看时 要携带用户ID,通过ID获取User  
<tr>
     <th>性别</th>
     <td>
      <% int gender = user.getGender(); %>
      <input type="radio" <%if(gender==1){%>checked="checked"<% } %>/>男
      <input type="radio" <%if(gender==2){%>checked="checked"<% } %>/>女
      </td>
 </tr>
 <tr>
      <th>学历</th>
      <td>
      <% int degree = user.getDegree(); %>
      <input type="radio" <%if(degree==1){%>checked="checked"<% } %>/>大专
      <input type="radio" <%if(degree==2){%>checked="checked"<% } %>/>本科
      <input type="radio" <%if(degree==3){%>checked="checked"<% } %>/>硕士
      <input type="radio" <%if(degree==4){%>checked="checked"<% } %>/>博士
      </td>
 </tr>
 <tr>
      <th>兴趣</th>
      <td>
      <% String intrest = user.getIntrest(); %>
      <input type="checkbox" <%if(intrest.contains("1")){%>checked="checked"<% } %>/>电影
      <input type="checkbox" <%if(intrest.contains("2")){%>checked="checked"<% } %>/>游戏
      <input type="checkbox" <%if(intrest.contains("3")){%>checked="checked"<% } %>/>运动
      <input type="checkbox" <%if(intrest.contains("4")){%>checked="checked"<% } %>/>学习
  </td>
 </tr>
以上的代码 就实现这一需求。

 

posted @ 2016-01-20 12:37  sqzuibang  阅读(1114)  评论(0编辑  收藏  举报