首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 网站开发 > JavaScript >

经过jsp动作元素将表单的内容和javabean的属性绑定,并显示出来

2012-11-12 
通过jsp动作元素将表单的内容和javabean的属性绑定,并显示出来%@ page languagejava importjava.uti

通过jsp动作元素将表单的内容和javabean的属性绑定,并显示出来
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    
    <title>My JSP 'FormP.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="FormP1.jsp" method="post">
    姓名: <input type="text" name="name"/><br/>
  年龄: <input type="text" name="age"/><br/>
  生日 <input type="text" name="birthday"/><br/>
    <input type="submit" value="submit"/><br/>
    
    
    </form>
  </body>
</html>









<%@ page language="java" import="java.util.*,java.text.*" pageEncoding="UTF-8"%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    
    <title>My JSP 'FormP1.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>
  <jsp:useBean id="Person" class="com.csdn.Bean.Person" scope="page"></jsp:useBean>
  
  <jsp:setProperty property="name" name="Person" param="name"/>
  <jsp:setProperty property="age" name="Person" param="age"/>
  <%
  String date = request.getParameter("birthday");
  DateFormat df = DateFormat.getDateInstance();
  Date date1 = df.parse(date);
    %>
    <jsp:setProperty property="birthday" name="Person" value="<%=date1 %>"/>
  <jsp:getProperty property="name" name="Person"/><br/>
  <jsp:getProperty property="age" name="Person"/><br/>
  
  ---------------------<br/>
  <%=Person.getName() %><br/>
  <%=Person.getAge() %><br/>
  <%=Person.getBirthday().toLocaleString() %><br/>
  
  </body>
</html>





package com.csdn.Bean;

import java.util.Date;
public class Person {
private String name;
private String age;
private Date birthday;

public Date getBirthday() {
return birthday;
}
public void setBirthday(Date birthday) {
this.birthday = birthday;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getAge() {
return age;
}
public void setAge(String age) {
this.age = age;
}

}

热点排行