1. Entity classes
1 Packagecom.zdsofe.javaBean.work;2 3 Public classStudent {4 5 PublicString name;6 PublicString sex;7 Public intAge ;8 Publicstring[] Hobby;9 PublicString Hobbys;Ten One Publicstring[] Gethobby () { A returnHobby; - } - Public voidsethobby (string[] hobby) { the This. Hobby =Hobby; - } - PublicString Gethobbys () { -String result= ""; + if( This. hobby.length>0) - { + A for(String str:hobby) at { -Result+=str+ ","; - } - - } -Result=result.substring (0, Result.length ()-1); inHobbys =result; - returnHobbys; to } + Public voidSethobbys (String hobbys) { - This. Hobbys =Hobbys; the } * PublicString GetName () { $ returnname;Panax Notoginseng } - Public voidsetName (String name) { the This. Name =name; + } A PublicString Getsex () { the returnsex; + } - Public voidsetsex (String sex) { $ This. Sex =sex; $ } - Public intGetage () { - returnAge ; the } - Public voidSetage (intAge ) {Wuyi This. Age =Age ; the } - Wu - About}
View Code
Action Elements for 2.jsp
1<% @pageImport= "Com.zdsofe.javaBean.work.Student"%>2<%@ page language= "java" contenttype= "text/html; Charset=utf-8 "3pageencoding= "UTF-8"%>4<! DOCTYPE HTML PUBLIC "-//w3c//dtd HTML 4.01 transitional//en" "HTTP://WWW.W3.ORG/TR/HTML4/LOOSE.DTD" >567<meta http-equiv= "Content-type" content= "text/html; Charset=utf-8 ">8<title>insert title here</title>9Ten<body> One A<!--used directly in the SCRIPT element- -<%/* - string[] s={"swimming", "mountain climbing", "Dancing"}; the Student student=new Student (); - Student.sethobby (s); - Out.print (Student.gethobbys ()); */ -%> + -<!--use the action elements of the JSP to +<% request.setcharacterencoding ("Utf-8"); %> A<!--Create entity classes-- at<jsp:usebean id= "User"class= "Com.zdsofe.javaBean.work.Student" ></jsp:useBean> -<!--Call the Set method-- -<jsp:setproperty property= "*" name= "user"/> - -<%--<jsp:setproperty property= "age" name= "user" value= "/>" -<jsp:getproperty property= "Age" name= "user"/>--%> in -<!--call the Get method-- to<jsp:getproperty property= "name" name= "user"/><br/> +<jsp:getproperty property= "Sex" name= "user"/><br/> -<jsp:getproperty property= "Hobbys" name= "user"/><br/> the *</body> $View Code3. Login Screen
1<%@ page language= "java" contenttype= "text/html; Charset=utf-8 "2pageencoding= "UTF-8"%>3<! DOCTYPE HTML PUBLIC "-//w3c//dtd HTML 4.01 transitional//en" "HTTP://WWW.W3.ORG/TR/HTML4/LOOSE.DTD" >456<meta http-equiv= "Content-type" content= "text/html; Charset=utf-8 ">7<title>insert title here</title>89<body>Ten<form action= "01.jsp" method= "POST" > OneUser name: <input type= "text" name= "name"/><br/> AGender: <input type= "Radio" name= "Sex" value= "male"/>male -<input type= "Radio" name= "Sex"/value= "women" > Women <br/> -Hobbies: <input type= "checkbox" name= "hobby" value= "swimming"/>Swimming the<input type= "checkbox" name= "hobby" value= "eat"/>Eat -<input type= "checkbox" name= "hobby" value= "Sleep"/> Sleep <br/> -<button type= "Submit" > Submit </button> -</form> + - +</body> AView CodeDevelopment model of JavaBean and JSP