输入页面 inputProperty
<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<base href="<%=basePath%>">
<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">
<!--
<link rel="stylesheet" type="text/css" href="styles.css">
-->
</head>
<body>
提交给conn_test1.jsp的表单: <br>
<form action="bean_test1.jsp" Method="post"><p>
输入ISBN:<input type=text name="paramisbn"><p>
输入书名:<input type=text name="paramtitle">
<input type=submit value="提交">
</form> <hr><p>
提交给bean_text2.jsp的表单:<br>
<form action="bean_test2.jsp" Method="post"><p>
输入ISBN:<input type=text name="isbn"><p>
输入书名:<input type=text name="title">
<input type=submit value="提交">
</form>
</body>
</html>
页面bean_test1.jsp
<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<jsp:useBean id="title" class="conn.Title" scope="page"/>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<base href="<%=basePath%>">
<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">
<!--
<link rel="stylesheet" type="text/css" href="styles.css">
-->
</head>
<body>
逐个设置Bean对象属性的测试结果:<br>
<%request.setCharacterEncoding("utf-8"); %>
<jsp:setProperty name="title"property="isbn"param="paramisbn"/>
<jsp:setProperty name="title"property="title"param="paramtitle"/>
<jsp:setProperty name="title"property="copyright"value="98780010-18-1"/>
书号:<jsp:getProperty name="title"property="isbn"/><br>
书名:<jsp:getProperty name="title"property="title"/><br>
版权号:<jsp:getProperty name="title"property="copyright"/><br>
</body>
</html>
页面bean_test2.jsp
<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<jsp:useBean id="title" class="conn.Title" scope="page"/>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<base href="<%=basePath%>">
<title>My JSP 'bean_test2.jsp' starting page</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">
<!--
<link rel="stylesheet" type="text/css" href="styles.css">
-->
</head>
<body>
自动获取表单参数并设置Bean对象属性的测试结果:<br>
<%request.setCharacterEncoding("utf-8"); %>
<jsp:setProperty name="title" property="*"/>
书号: <jsp:getProperty name="title" property="isbn"/></br>
书名: <jsp:getProperty name="title" property="title"/></br>
</body>
</html>
图书表Title
//数据bean,用于封装图书表Titles中的一本图书记录
package conn;
public class Title {
private String isbn; //isbn号
private String title; //书名
private String copyright; //版权
private String imageFile; //封面图像文件名称
private int editionNumber; //版本号
private int publisherId; //出版商ID
private float price; //价格
public String getIsbn() {
return isbn;
}
public void setIsbn(String isbn) {
this.isbn = isbn;
}
public String getTitle() {
return title;
}
public void setTitle(String title) {
this.title = title;
}
public String getCopyright() {
return copyright;
}
public void setCopyright(String copyright) {
this.copyright = copyright;
}
public String getImageFile() {
return imageFile;
}
public void setImageFile(String imageFile) {
this.imageFile = imageFile;
}
public int getEditionNumber() {
return editionNumber;
}
public void setEditionNumber(int editionNumber) {
this.editionNumber = editionNumber;
}
public int getPublisherId() {
return publisherId;
}
public void setPublisherId(int publisherId) {
this.publisherId = publisherId;
}
public float getPrice() {
return price;
}
public void setPrice(float price) {
this.price = price;
}
}
网友评论