日期:2014-05-17 浏览次数:20704 次
//文件 BookHotel.jsp <jsp:useBean id='roomBooking' scope='page' class='beans.HotelBean' /> <jsp:setProperty name='roomBooking' property='*' /> <html> <head><title>Bean test</title></head> <body> <h2> <%=roomBooking.getName()%> to stay for <%= roomBooking.getnNights() %> nights. </h2> </body> </html>
//HotelForm.jsp <jsp:useBean id="roomBooking" scope="page" class="beans.HotelBean" /> <jsp:setProperty name="roomBooking" property="*" /> <html> <body> <h3 align="center">Welcome to the Hotel California</h3> <form method="POST" action="BookHotel.jsp"> <p>Name: <input type="text" name="name" size="20"></p> <p>How many nights: <select size="1" name="nNights"> <option selected="">1</option> <option>2</option> <option>3</option> </select> </p> <p><input type="submit" value="Submit" name="B1"></p> </form> </body> </html>
//javabean. package beans; public class HotelBean { String name; int nNights; public String getName() { return name; } public void setName(String name) { this.name = name; } public int getnNights() { return nNights; } public void setnNights(int nNights) { this.nNights = nNights; } }