日期:2014-05-17 浏览次数:20869 次
package ch07; public class NameHandler { private String username; private String userhid; public NameHandler(){ username = null; userhid = null; } public void setUsername( String name ){ username = name; } public String getUsername() { return username; } public void setUserhid(Sting hid) { userhid=hid; } public String getUserhid() { return userhid; }
<%@ page contentType="text/html;charset=gb2312"%> <jsp:useBean id="mybean" scope="session" class="ch07.NameHandler" /> <jsp:setProperty name="mybean" property="*" /> <% if(request.getParameter("username")!= null ) { response.sendRedirect("response.jsp"); } %> <html> <head> <title>Hello, User</title> </head> <body> <h2>Hello,my name is 柳永坡. What's yours?</h2> <form method="post" action="hellouser.jsp"> <input type="text" name="username" size="25"> <input type="text" name="userhid" size="25"><br> <input type="submit" value="提交"> <input type="reset" value="重置"> </form> </body> </html>
<jsp:useBean id="mybean" scope="session" class="ch07.NameHandler" /> <html> <head> <title>Hello, <%=mybean.getUsername()%></title> </head> <body> <h1>Hello, <jsp:getProperty name="mybean" property="username" /> </h1> <h2> hid= <%=mybean.getUserhid()%> </h2> </body> </html>