JavaBean和jsp的开发模型

原文链接: http://www.cnblogs.com/zclqian/p/7235628.html

1.实体类

 1 package com.zdsofe.javaBean.work;
 2 
 3 public class Student {
 4 
 5     public String name;
 6     public String sex;
 7     public int age;
 8     public String[] hobby;
 9     public String hobbys;
10     
11     public String[] getHobby() {
12         return hobby;
13     }
14     public void setHobby(String[] hobby) {
15         this.hobby = hobby;
16     }
17     public String getHobbys() {
18         String result="";
19         if(this.hobby.length>0)
20         {
21             
22             for(String str:hobby)
23             {
24                 result+=str+",";
25             }
26             
27         }
28         result=result.substring(0, result.length()-1);
29         hobbys = result;        
30         return hobbys;
31     }
32     public void setHobbys(String hobbys) {
33         this.hobbys = hobbys;
34     }
35     public String getName() {
36         return name;
37     }
38     public void setName(String name) {
39         this.name = name;
40     }
41     public String getSex() {
42         return sex;
43     }
44     public void setSex(String sex) {
45         this.sex = sex;
46     }
47     public int getAge() {
48         return age;
49     }
50     public void setAge(int age) {
51         this.age = age;
52     }
53     
54     
55     
56 }
View Code

2.jsp的动作元素

 1 <%@page import="com.zdsofe.javaBean.work.Student"%>
 2 <%@ page language="java" contentType="text/html; charset=UTF-8"
 3     pageEncoding="UTF-8"%>
 4 
 5 
 6 
 7 
 8 Insert title here
 9 
10 
11 
12 
13 <%/* 
14      String[] s={"游泳","爬山","跳舞"};
15      Student student=new Student();
16      student.setHobby(s);
17      out.print(student.getHobbys());  */
18 %>
19 
20 
21 <% request.setCharacterEncoding("utf-8"); %>
22 
23     class="com.zdsofe.javaBean.work.Student">
24     
25     
26     
27     <%-- 
28      --%>
29     
30     
31     
32
33
34 35 36
View Code

3.登录界面

 1 <%@ page language="java" contentType="text/html; charset=UTF-8"
 2     pageEncoding="UTF-8"%>
 3 
 4 
 5 
 6 
 7 Insert title here
 8 
 9 
10 
11 用户名:
12 性别:13
14 爱好: 游泳 15 吃饭 16 睡觉
17 18
19 20 21 22
View Code

 

转载于:https://www.cnblogs.com/zclqian/p/7235628.html

你可能感兴趣的:(JavaBean和jsp的开发模型)