JavaBean和jsp的開發模型

來源:互聯網
上載者:User

標籤:play   inpu   code   dtd   property   coding   方法   new   gif   

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 <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> 5 <html> 6 <head> 7 <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> 8 <title>Insert title here</title> 9 </head>10 <body>11 12 <!--直接在指令碼元素中使用  -->13 <%/* 14      String[] s={"遊泳","爬山","跳舞"};15      Student student=new Student();16      student.setHobby(s);17      out.print(student.getHobbys());  */18 %>19 20 <!-- 利用jsp的動作元素來使用 -->21 <% request.setCharacterEncoding("utf-8"); %>22 <!-- 建立實體類 -->23     <jsp:useBean id="user" class="com.zdsofe.javaBean.work.Student"></jsp:useBean>24     <!--  調用set方法-->25     <jsp:setProperty property="*" name="user"/>26     27     <%-- <jsp:setProperty property="age" name="user" value="34"/>28     <jsp:getProperty property="age" name="user"/> --%>29     30     <!-- 調用get方法 -->31     <jsp:getProperty property="name" name="user" /><br/>32     <jsp:getProperty property="sex" name="user"/><br/>33     <jsp:getProperty property="hobbys" name="user"/><br/>34     35 </body>36 </html>
View Code

3.登入介面

 1 <%@ page language="java" contentType="text/html; charset=UTF-8" 2     pageEncoding="UTF-8"%> 3 <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> 4 <html> 5 <head> 6 <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> 7 <title>Insert title here</title> 8 </head> 9 <body>10 <form action="01.jsp" method="post">11 使用者名稱:<input type="text" name="name"/><br/>12 性別:<input type="radio" name="sex" value="男"/>男13      <input type="radio" name="sex"/ value="女">女<br/>14 愛好: <input type="checkbox" name="hobby" value="遊泳"/>遊泳15      <input type="checkbox" name="hobby" value="吃飯" />吃飯16      <input type="checkbox" name="hobby" value="睡覺"/>睡覺<br/>17      <button type="submit">提交</button>18 </form>19 20 21 </body>22 </html>
View Code

 

JavaBean和jsp的開發模型

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.