时间:2023-09-08 16:36:01 | 来源:网站运营
时间:2023-09-08 16:36:01 来源:网站运营
Java Web实验报告: Web组件重用与JavaBeans:一、实验目的<%@ page pageEncoding="UTF-8" %><hr><center><h1><font size="+3" color="red">新世纪 </font><font size="+3" color="purple">网上书店</font></h1></center><hr>
【步骤2】在frag文件夹中创建footer.jsp文件<%@ page pageEncoding="UTF-8" %><hr><center><em>Copyright © 2008 New Century Web Bookstore, Inc. </em></center>
【步骤3】项目文件夹中创建main.jsp文件代码(注:不要放在上述的frag文件夹)<%@ page contentType="text/html;charset=gb2312" %><html><head><title>New Century Web Bookstore</title></head><body bgcolor="#FFFFFF"><%@ include file="/WEB-INF/frag/header.html" %> <table border=0 cellspacing=5 cellpadding=5 width="100%"> <tr><td> <p align="center"><b>欢迎光临新世纪网上书店!</b></p> </td> </tr> <tr> <td> <p align="center"><b><a href="/bookstore/catalog">开始购买图书</a></b> </td> </tr></table><%@ include file="/WEB-INF/frag/footer.jsp" %></body></html>
【步骤4】最后执行main.jsp文件,结果如下图所示:<%@ page contentType="text/html;charset=gb2312" %><html><head><title>New Century Web Bookstore</title></head><body bgcolor="#FFFFFF"><jsp:include page="/WEB-INF/frag/header.jsp" flush="true"/><table border=0 cellspacing=5 cellpadding=5 width="100%"> <tr><td> <p align="center"><b>欢迎光临新世纪网上书店!</b></p> </td> </tr> <tr> <td><p align="center"><b><a href="/bookstore/catalog">开始购买图书</a></b> </td> </tr></table><jsp:include page="/WEB-INF/frag/footer.jsp" flush="true"/></body></html>
**************************************************<%@ page pageEncoding="UTF-8" %><hr><center><h1><font size="+3" color="red">新世纪 </font><font size="+3" color="purple">网上书店</font></h1></center><hr>
(三)<jsp:forward>标准动作的使用<%@ page contentType="text/html;charset=gb2312" %><html><head><title>Forward Test</title></head> <body> <jsp:forward page="forwardTo.jsp"> <jsp:param name="userName" value="Hacker"/> </jsp:forward> </body></html>
【步骤2】forwardTo.jsp的代码如下:<%@ page contentType="text/html;charset=gb2312" %><% String userName = request.getParameter("userName"); String welcomeStr = "欢迎光临本站"; welcomeStr = userName+","+welcomeStr; out.print(welcomeStr); %>
执行action_forward.jsp页面的结果如下:package com.beans;public class UserBean { private String username; private String password; private String email; public UserBean(){} public void setUsername(String username){ this.username = username; } public void setPassword(String password){ this.password = password; } public void setEmail(String email){ this.email = email; } public String getUsername(){ return username; } public String getPassword(){ return password; } public String getEmail(){ return email; } }【步骤2】登录页面login.html代码如下:<html><body>Please input:<br><form action="display.jsp">UserName:<input type="text" name="username"><br>Password:<input type="password" name="password"><br>Email:<input type="text"name="email"><br><input type="submit" value="提交"></form></body></html>
【步骤3】display.jsp页面使用JavaBeans显示输入的信息。<%@ page import="com.beans.UserBean" %><jsp:useBean id="user" class="com.beans.UserBean" scope="session"/><jsp:setProperty name="user" property="*"/><html><body> UserName:<jsp:getProperty name="user" property="username"/><br> Password:<jsp:getProperty name="user" property="password"/><br> Email:<jsp:getProperty name="user" property="email"/><br></body></html>
四、实验总结关键词:实验,报告