1.User.java代码(JavaBean):
package com.dao;
public class User {
private String userID;
private String userName;
private String userID;
private String userName;
public User() {
}
}
public User(String userID, String userName) {
this.userID = userID;
this.userName = userName;
}
this.userID = userID;
this.userName = userName;
}
/**
* @return the userID
*/
public String getUserID() {
return userID;
}
* @return the userID
*/
public String getUserID() {
return userID;
}
/**
* @param userID
* the userID to set
*/
public void setUserID(String userID) {
this.userID = userID;
}
* @param userID
* the userID to set
*/
public void setUserID(String userID) {
this.userID = userID;
}
/**
* @return the userName
*/
public String getUserName() {
return userName;
}
* @return the userName
*/
public String getUserName() {
return userName;
}
/**
* @param userName
* the userName to set
*/
public void setUserName(String userName) {
this.userName = userName;
}
* @param userName
* the userName to set
*/
public void setUserName(String userName) {
this.userName = userName;
}
}
2.getuserinfo.html代码清单:
<html>
<head>
<meta http-equiv="Content-Type" content="text/html" charset="GB2312">
<title>输入用户信息</title>
</head>
<body>
<h2>JSP中使用JavaBean编程<h2>
<hr>
本实例演示通过Java Bean接收表单数据。<hr>
请输入用户信息:
<form action="showuser.jsp" method="post">
<table border="1">
<tbody>
<tr>
<td align="right">y用户号:</td>
<td><input type="text" name="userID" size="9" maxlength="20"></td>
</tr>
<tr>
<tr>
<td align="right">姓 名:</td>
<td><input type="text" name="userName" size="9" maxlength="20"></td>
</tr>
<tr>
</tbody>
</table>
<br>
<input type="hidden" name="userId" value="OOOO">
<input type="submit" value="提交" >
<input type="reset" value="清除">
</form>
<hr>
</body>
</html>
<head>
<meta http-equiv="Content-Type" content="text/html" charset="GB2312">
<title>输入用户信息</title>
</head>
<body>
<h2>JSP中使用JavaBean编程<h2>
<hr>
本实例演示通过Java Bean接收表单数据。<hr>
请输入用户信息:
<form action="showuser.jsp" method="post">
<table border="1">
<tbody>
<tr>
<td align="right">y用户号:</td>
<td><input type="text" name="userID" size="9" maxlength="20"></td>
</tr>
<tr>
<tr>
<td align="right">姓 名:</td>
<td><input type="text" name="userName" size="9" maxlength="20"></td>
</tr>
<tr>
</tbody>
</table>
<br>
<input type="hidden" name="userId" value="OOOO">
<input type="submit" value="提交" >
<input type="reset" value="清除">
</form>
<hr>
</body>
</html>
3.showuser.jsp代码:
@ page contentType="text/html"errorPage="err.jsp"%>
<%@page import="com.dao.User"%>
<html>
<body>
<center>
<%!String title="显示用户信息";%>
用户输入的信息如下:<br>
<jsp:useBean id="userinfo" class="com.dao.User"/>
<jsp:setProperty name="userinfo"property="*"/>
<table border="1">
<tbody>
<tr><td>用户号</td>
<td><jsp:getProperty name="userinfo"property="userID"/></td></tr>
<tr><td>用户号</td>
<td><jsp:getProperty name="userinfo"property="userID"/></td></tr>
<tr><td>用户
</td><td>
<jsp:getProperty name="userinfo"property="userName"/>
</td></tr>
</tbody>
</table>
</center>
</body>
</html>
<%@page import="com.dao.User"%>
<html>
<body>
<center>
<%!String title="显示用户信息";%>
用户输入的信息如下:<br>
<jsp:useBean id="userinfo" class="com.dao.User"/>
<jsp:setProperty name="userinfo"property="*"/>
<table border="1">
<tbody>
<tr><td>用户号</td>
<td><jsp:getProperty name="userinfo"property="userID"/></td></tr>
<tr><td>用户号</td>
<td><jsp:getProperty name="userinfo"property="userID"/></td></tr>
<tr><td>用户
</td><td>
<jsp:getProperty name="userinfo"property="userName"/>
</td></tr>
</tbody>
</table>
</center>
</body>
</html>