JSP上机实习报告课程名称JSP开发技术任课老师赵丹专业信息管理与信息系统学号 *********** 姓名胡斌JSP上机实习报告第一题一、题目在JSP中利用Java代码计算出1+1的结果,然后在页面中显示计算结果,实现过程如下:1、创建动态Web项目,并创建JSP文件2、在JSP文件中编写Java代码计算出1+1的结果,并将结果打印到页面中二、代码<%@ page language="java"import="java.util.*"pageEncoding="ISO-8859-1"%><!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"><html><head><title>My JSP 'hb1.jsp' starting page</title><meta http-equiv="pragma" content="no-cache"><meta http-equiv="cache-control" content="no-cache"><meta http-equiv="expires" content="0"><meta http-equiv="keywords" content="keyword1,keyword2,keyword3"> <meta http-equiv="description" content="This is my page"><!--<link rel="stylesheet" type="text/css" href="styles.css">--></head><body><% int i=1,j=1;out.println("1+1=");out.print(i+j);%> <br></body></html>三、运行结果第二题一、题目应用Eclipse新建一个Web项目,并在该项目的根目录下创建index.jsp和welcome.jsp文件,要求给项目实现如下功能:当访问index.jsp文件后,会自动转发到welcome.jsp页面二、代码1.index.jsp部分<%@ page language="java"import="java.util.*"pageEncoding="ISO-8859-1"%><!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"><html><head><title>My JSP 'index.jsp' starting page</title><meta http-equiv="pragma" content="no-cache"><meta http-equiv="cache-control" content="no-cache"><meta http-equiv="expires" content="0"><meta http-equiv="keywords" content="keyword1,keyword2,keyword3"> <meta http-equiv="description" content="This is my page"><!--<link rel="stylesheet" type="text/css" href="styles.css">--></head><body><jsp:forward page="welcome.jsp"/> <br></body></html>2.Welcome.jsp部分<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%><!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"><html><head><title>My JSP 'welcome.jsp' starting page</title><meta http-equiv="pragma" content="no-cache"><meta http-equiv="cache-control" content="no-cache"><meta http-equiv="expires" content="0"><meta http-equiv="keywords" content="keyword1,keyword2,keyword3"> <meta http-equiv="description" content="This is my page"><!----></head><body>跳转成功!Good Job! <br></body></html>三、运行结果第三题一、题目编写一个简单的留言薄,写入留言提交后显示留言内容。
二、代码1.doword.jsp部分<%@ page language="java" contentType="text/html; charset=gb2312"%><!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"><html><head><title>留言簿</title><meta http-equiv="pragma" content="no-cache"><meta http-equiv="cache-control" content="no-cache"><meta http-equiv="expires" content="0"><meta http-equiv="keywords" content="keyword1,keyword2,keyword3"> <meta http-equiv="description" content="This is my page"><!----></head><form id="form1" name="form1" method="post" action="message.jsp"> 留言:<textarea name="content" rows="2" cols="20"></textarea><br><br>留言人:<textarea name="username" rows="2" cols="5"></textarea><br><br><input type="submit" name="Submit" value="提交"/><input type="reset" name="Submit2" value="重置"/></form><body></body></html>2.message.jsp部分<%@ page language="java" contentType="text/html; charset=gb2312"%><!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"><html><head></head><body><%@ page import="hbw.dostring" %><%request.setCharacterEncoding("gb2312");String username=request.getParameter("username");String content=request.getParameter("content");content=dostring.change(content);%>留言内容是:<%=content %><br><br>留言人是:<%=username %></body></html>三、运行结果1.留言输入2.留言展示第四题一、题目应用Eclipse创建一个名为BookInfo的值JavaBean,要求该JaaBean具有name,price,stock和author简单属性,属性类型为string二、代码package hbe;public class bookinfo {private String name;private String price;private String stock;private String author;public String getName() {return name;}public void setName(String name) { = name;}public String getPrice() {return price;}public void setPrice(String price) {this.price = price;}public String getStock() {return stock;}public void setStock(String stock) {this.stock = stock;}public String getAuthor() {return author;}public void setAuthor(String author) {this.author = author;}}第五题一、题目应用Eclipse创建一个名为DoString的工具JavaBean,用来转换字符串中“<”与“>”字符。