案例

来源:互联网 发布:手机自动抢货秒杀软件 编辑:程序博客网 时间:2024/04/28 04:30
 

package com.hbsi.bean;

import java.util.Date;

public class Persion {
 private String name;
 private int age;
 private Date birthday;
 
 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 Date getBirthday() {
  return birthday;
 }
 public void setBirthday(Date birthday) {
  this.birthday = birthday;
 }
 public Persion() {
  super();
  // TODO Auto-generated constructor stub
 }
 public Persion(String name, int age, Date birthday) {
  super();
  this.name = name;
  this.age = age;
  this.birthday = birthday;
 }
}

<body background="image/12.jpg"><center>
  <font size="8" color="red">提交表单</font>
    <form action="persion.jsp" method="post">
    用户名:<input type="text" name="username"/><br/><br/>
    年&nbsp;&nbsp;&nbsp;龄:<input type="text" name="age"/><br/><br/>
    生&nbsp;&nbsp;&nbsp;日:<input type="text" name="birthday"/><br/><br/>
    <input type="submit" value="提交"/><input type="reset" value="重置"/>
    </form>
  </body>

<body>
   <%
    request.setCharacterEncoding("UTF-8");
    %>
  <jsp:useBean id="persion" class="com.hbsi.bean.Persion" scope="page"></jsp:useBean>
    <jsp:setProperty property="name" name="persion" param="username"/>
    <jsp:setProperty property="age" name="persion" param="age"/>
    <%
    String date=request.getParameter("birthday");
    DateFormat df=DateFormat.getDateInstance();
    Date date1 = df.parse(date);
     %>
     <jsp:setProperty property="birthday" name="persion" value="<%=date1 %>"/>
     <%="姓名:"+persion.getName() %><br/>
     <%="年龄:"+persion.getAge() %><br/>
     <%="生日:"+persion.getBirthday().toLocaleString() %>
  
  </body>