如图:
itcast.Person 代码
package itcast;
public class Person {
private String name;
private int age;
private String sex;
private String add;
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public int getAge() {
return age;
}
public void setAge(int age) {
this.age = age;
}
public String getSex() {
return sex;
}
public void setSex(String sex) {
this.sex = sex;
}
public String getAdd() {
return add;
}
public void setAdd(String add) {
this.add = add;
}
}
index.jsp代码
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"
errorPage="error.jsp"%>
<%
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 'error.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>
<form action="reg.jsp" method="post">
姓名:<input type="text" name="name"><br>
年龄:<input type="text" name="age"><br>
性别:<input type="text" name="sex"><br>
住址:<input type="text" name="add"><br>
<input type="submit" value="添 加">
</form>
</body>
</html>
reg.jsp代码
<%@ 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>My JSP 'reg.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>
<%request.setCharacterEncoding("utf-8") ;%>
<jsp:useBean id="person" class="itcast.Person" scope="page">
<jsp:setProperty name="person" property="*"/>
</jsp:useBean>
姓名:<jsp:getProperty property="name" name="person"/><br>
年龄:<jsp:getProperty property="age" name="person"/><br>
性别:<jsp:getProperty property="sex" name="person"/><br>
住址:<jsp:getProperty property="add" name="person"/>
</body>
</html>