要求编写两个JSP页面:input.jsp和show.jsp。编写一个名字为car的javaBean,其中car由car.class类负责创建。
input.jsp页面提供一个表单,其中表单允许用户输入汽车的牌号、名称和生产日期,该表单将用户输入的信息提交给当前页面,当前页面调用的名字为car的bean,并使用表单提交的数据设置car的有关属性的值。要求在input.jsp提供一个超链接,以便用户单击这个超链接访问show.jsp页面。
show.jsp调用名字为car的bean,并显示该bean的各个属性的值。
编写的car.java应当有汽车号码、名称和生产日期的属性,并提供相应的getXxx和setXxx方法,来获取和修改这些属性的值。
input.jsp
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>汽车表单</title>
</head>
<body>
<form action="show.jsp" method="get">
车牌号:<input type=text name=id /> 名称: <input type=text name=name />
生产日期:<input type=text name=date /><br> <input type=submit
value=提交 />
</form>
<a href="show.jsp">链接至show.jsp页面</a>
</body>
</html>
show.jsp
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>show</title>
</head>
<body>
<jsp:useBean id="car" scope="request" class="com.chap07.car" />
<jsp:setProperty name="car" property="*"/>
汽车牌号:<%=car.getId() %><br>
名称:<%=car.getName() %><br>
生产日期:<%=car.getDate() %>
</body>
</html>
car.java
package com.chap07;
/**
* @author yilong
* 创建时间:2017-4-12 下午4:15:11
*
*/
public class car {
private int id;
private String name;
private String date;
public car() {
super();
}
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getDate() {
return date;
}
public void setDate(String date) {
this.date = date;
}
}