1 / 8

编写 JavaBean 必须满足以下几点 : 所有的 JavaBean 必须放在一个包中 JavaBean 必须声明成 public class 类型 所有的属性必须封装

编写 JavaBean 必须满足以下几点 : 所有的 JavaBean 必须放在一个包中 JavaBean 必须声明成 public class 类型 所有的属性必须封装 设置和取得属性可以通过 set,get [ 注 ] 使用 jsp 标签调用 JavaBean 时必须有一个无参的构造方法. Tomcat 服务器 , 在默认情况下 是不能读取修改后的 JavaBean, 如果要读取有 2 种方法 : 1) 重起服务器 2) 配置参数 :<Context path=“/xxx” docBase=“url” reloadable=“true”/>.

chanel
Download Presentation

编写 JavaBean 必须满足以下几点 : 所有的 JavaBean 必须放在一个包中 JavaBean 必须声明成 public class 类型 所有的属性必须封装

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. 编写JavaBean必须满足以下几点: • 所有的JavaBean必须放在一个包中 • JavaBean必须声明成public class类型 • 所有的属性必须封装 • 设置和取得属性可以通过set,get • [注]使用jsp标签调用JavaBean时必须有一个无参的构造方法

  2. Tomcat服务器,在默认情况下 是不能读取修改后的JavaBean,如果要读取有2种方法: • 1)重起服务器 • 2)配置参数:<Context path=“/xxx” docBase=“url” reloadable=“true”/>

  3. 设置属性的方法有4种: • <jsp:setPorperty name=“myBean” property=“*”/> • <jsp:setPorperty name=“myBean” property=“myProperty”/> • <jsp:setPorperty name=“myBean” property=“myProperty” param=“ParamName”/> • <jsp:setPorperty name=“myBean” property=“myProperty” vlaue=“MyValue”/>

  4. SimpleBean.java package com.ji.java.bean public class SimpleBean { private String name ; private String password ; // 如果没有指定构造方法,则会自动生成一无参的什么都不做的构造方法 public SimpleBean() { System.out.println(" public SimpleBean() .") ; } public void setName(String name) { this.name = name ; }

  5. public void setPassword(String password) { this.password = password ; } public String getName() { return this.name ; } public String getPassword() { return this.password ; } }

  6. 01.jsp <%@page contentType="text/html;charset=gb2312"%> <%@page import="com.jida.javabean.*"%> <% // 实例化对象 SimpleBean sb = new SimpleBean() ; sb.setName("jida") ; sb.setPassword("403") ; %> <h1>姓名:<%=sb.getName()%></h1> <h1>密码:<%=sb.getPassword()%></h1>

  7. Login.jsp <form action="02.jsp" method="post"> 用户名:<input type="text" name="name"><br> 密&nbsp;&nbsp;码:<input type="text" name="password"><br> <input type="submit" value="提交"> <input type="reset" value="重置"> </form>

  8. 02.jsp <%@page contentType="text/html;charset=gb2312"%> <jsp:useBean id="sb" scope="page" class="com.jida.javabean.SimpleBean"/> <jsp:setProperty name="sb" property="*"/> <%-- // 如果有20个数据需要设置,则使用JavaBean的设置属性方式,可以自动完成 // 代替以下代码 sb.setName(request.getParameter("name")) ; sb.setPassword(request.getParameter("password")) ; --%> <h1>姓名:<%=sb.getName()%></h1> <h1>密码:<%=sb.getPassword()%></h1>

More Related