jsp之熟悉JavaBean的使用

要求编写两个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应有汽车号码,名称和生产日期得属性,并提供相应得get,set方法,来获取和修改这些属性得值

input.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 'input.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">
	-->
    <%request.setCharacterEncoding("GB2312"); %>
  </head>
  
  <body>
    <jsp:useBean id="car" class="pratice_one.Car" scope="session"></jsp:useBean>
    <form action="" method="post">
        车牌号:<input  type="text" name="carNumber"/><br>
        名称:<input type="text" name="carName"/><br>
        生产日期:<input type="text" name="carDate"/><br>
        <input type="submit" name="submit" value="提交"/>
    </form>
    <jsp:setProperty property="*" name="car" />
    <a href="show.jsp">点击跳转show.jsp页面</a>
  </body>
</html>

show.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 'show.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">
	-->
    <%request.setCharacterEncoding("Gb2312"); %>
  </head>
  <jsp:useBean id="car" scope="session" class="pratice_one.Car"></jsp:useBean>
  
  汽车号码:<jsp:getProperty property="carNumber" name="car" />
  汽车名称:<jsp:getProperty property="carName" name="car" />
  生产日期: <jsp:getProperty property="carDate" name="car" />
  <body>
    
  </body>
</html>

Car.java

package pratice_one;

public class Car {
    private String carNumber;
    private String carName;
    private String carDate;
	public String getCarNumber() {
		return carNumber;
	}
	public void setCarNumber(String carNumber) {
		this.carNumber = carNumber;
	}
	public String getCarName() {
		return carName;
	}
	public void setCarName(String carName) {
		this.carName = carName;
	}
	public String getCarDate() {
		return carDate;
	}
	public void setCarDate(String carDate) {
		this.carDate = carDate;
	}
}

相关推荐
©️2020 CSDN 皮肤主题: Age of Ai 设计师:meimeiellie 返回首页