<jsp:useBean id=”name” class=”classname” scope={“page\request\session\application”}/> |
<jsp:setProperty name=”beanName” propertyDetails/> |
<jsp:useBean id=”usersession” scope=”session” class=”com.user.UserSession”>
<jsp:setProperty name=”usersession” property=”name” value=”Tom”/>
</jsp:useBean> |
<jsp:getProperty name=”beanName” propertry=”propertyName”/> |
<jsp:useBean id=”usersession” scope=”session” class=”com.user.UserSession”>
<jsp:getProperty name=”usersession” property=”name” />
</jsp:useBean> |
package com.zj.sample;
import java.io.Serializable;
/**
* Create a JavaBean
*/
public class UserBean implements Serializable {
private static final long serialVersionUID =
public String userName;
public String password;
public int age;
public UserBean() {}
public void setUserName(String name) {
this.userName = name;
}
public void setPassword(String password) {
this.password = password;
}
public void setAge(int age) {
this.age = age;
}
public String getUserName() {
return this.userName;
}
public String getPassword() {
return this.password;
}
public int getAge() {
return this.age;
}
} |
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=GB18030">
<title>Reg</title>
</head>
<body>
User Info:<br><hr>
<form method="get" action="reg.jsp">
<table>
// name="userName"对应UserBean属性
<tr><td>Name:<input name="userName" type="text"></td></tr>
//name="password"对应UserBean属性
<tr><td>Password:<input name="password" type="password"></td></tr>
//name="age"对应UserBean属性
<tr><td>Age:<input name="age" type="text"></td></tr>
<tr><td><input type="submit" value="submit"></td></tr>
</table>
</form>
</body>
</html> |
<%@ page language="java" contentType="text/html; charset=GB18030"
pageEncoding="GB18030"%>
<!DOCTYPE HTML PUBLIC "-//W
<jsp:useBean id="user" scope="page" class="com.zj.sample.UserBean" />
<jsp:setProperty name="user" property="*" />//使用property="*"
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=GB18030">
<title>Show Info</title>
</head>
<body>
Reg successful!
// property="userName"对应UserBean属性
<br><jsp:getProperty name="user" property="userName" />
// property="password"对应UserBean属性
<br><jsp:getProperty name="user" property="password" />
// property="age"对应UserBean属性
<br><jsp:getProperty name="user" property="age" />
<br>
</body>
</html> |
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=GB18030">
<title>Reg</title>
</head>
<body>
User Info:<br><hr>
<form method="get" action="reg2.jsp">
<table>
<tr><td>Name:<input name="USERNAME" type="text"></td></tr>
<tr><td>Password:<input name="PASSWORD" type="password"></td></tr>
<tr><td>Age:<input name="AGE" type="text"></td></tr>
<tr><td><input type="submit" value="submit"></td></tr>
</table>
</form>
</body>
</html> |
<%@ page language="java" contentType="text/html; charset=GB18030"
pageEncoding="GB18030"%>
<!DOCTYPE HTML PUBLIC "-//W
<jsp:useBean id="user" scope="page" class="com.zj.sample.UserBean"/>
// property="userName"对应UserBean属性,param="USERNAME"对应表单属性
<jsp:setProperty name="user" property="userName" param="USERNAME"/>
// property="password"对应UserBean属性,param="PASSWORD"对应表单属性
<jsp:setProperty name="user" property="password" param="PASSWORD"/>
// property="age"对应UserBean属性,param="AGE"对应表单属性
<jsp:setProperty name="user" property="age" param="AGE"/>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=GB18030">
<title>Show Info</title>
</head>
<body>
Reg successful!<br>
// property="userName"对应UserBean属性
Name:<jsp:getProperty name="user" property="userName"/><br>
// property="password"对应UserBean属性
Password:<jsp:getProperty name="user" property="password"/><br>
// property="age"对应UserBean属性
Age:<jsp:getProperty name="user" property="age"/><br>
</body>
</html> |