日期:2014-05-17 浏览次数:20647 次
<html> <head> <base href="<%=basePath%>"> <title>My JSP 'myBean.jsp' starting page</title> </head> <body> <form action="student.jsp"> <p>学号: <input type="text" name="id"> </p> <p>年龄: <input type="text" name="age"> </p> <p><input type="submit" value="提交"/></p> </form> </body> </html>
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%> <% String path = request.getContextPath(); String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/"; %> <jsp:useBean id="student" class="com.javabean.Bean"></jsp:useBean> <jsp:setProperty property="*" name="student"/> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <html> <head> <base href="<%=basePath%>"> <title>My JSP 'student.jsp' starting page</title> </head> <body> 学号:<%=student.getId() %> 年龄:<%=student.getAge() %> </body> </html>
package com.javabean; public class Bean { private String id,age; public Bean(){ } public void setId(String id){ this.id=id; } public String getId(){ return id; } public void setAge(String age){ this.age=age; } public String getAge(){ return age; } }