Development model of JavaBean and JSP

Source: Internet
Author: User
Tags button type

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 Code

3. 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 Code

Development model of JavaBean and JSP

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.