JavaBean的温习。

JavaBean的温习。

一、先创建Bean实例。程序如下:

package com.test.bean;

public class GoodsBean {
	
	private String	productName;
	private String	productType;
	
	public String getProductName() {
		return productName;
	}
	public void setProductName(String productName) {
		this.productName = productName;
	}
	public String getProductType() {
		return productType;
	}
	public void setProductType(String productType) {
		this.productType = productType;
	}
	
	
}

 

二、JSP 页面使用JavaBean如下:

<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>


<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    <title>JavaBean 的学习</title>
	<meta http-equiv="pragma" content="no-cache">
	<meta http-equiv="cache-control" content="no-cache">
	<meta http-equiv="expires" content="0">    
	<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
	<meta http-equiv="description" content="This is my page">

  </head>
  
  <body>
  	<jsp:useBean id="product" scope="session" class="com.test.bean.GoodsBean"/>
  	<jsp:setProperty name="product" property="productName" value="气门"/>
  	<jsp:setProperty name="product" property="productType" value="10.258"/>
   	产品名:<jsp:getProperty name="product" property="productName"/><br/>
   	类  型:<jsp:getProperty name="product" property="productType"/>
   	<%
   		product.setProductName("轴承");
   		product.setProductType("56.25");
   	%>
   	<br/>
   	产品名:<%=product.getProductName() %><br/>
   	类  型:<%=product.getProductType() %>
  </body>
</html>

 

记住 JavaBean 在JSP中的应用。

你可能感兴趣的:(html,jsp,bean,cache)