jsp实现留言功能

上传人:re****.1 文档编号:556593538 上传时间:2023-10-25 格式:DOC 页数:5 大小:157.50KB
返回 下载 相关 举报
jsp实现留言功能_第1页
第1页 / 共5页
jsp实现留言功能_第2页
第2页 / 共5页
jsp实现留言功能_第3页
第3页 / 共5页
jsp实现留言功能_第4页
第4页 / 共5页
jsp实现留言功能_第5页
第5页 / 共5页
亲,该文档总共5页,全部预览完了,如果喜欢就下载吧!
资源描述

《jsp实现留言功能》由会员分享,可在线阅读,更多相关《jsp实现留言功能(5页珍藏版)》请在金锄头文库上搜索。

1、课程名称Web程序设计实验日期 实验项目名称JavaBean的应用实验地点实验类型验证型 设计型综合型 学 时一、实验目的及要求(本实验所涉及并要求掌握的知识点)1、 理解 JavaBean 的作用 2、 掌握JavaBean定义方法 3、 掌握jsp 页面中调用 JavaBean的两种方法,熟练掌握标签指令调用JavaBean的方法。4、 理解JavaBean的作用范围。 二、实验环境(本实验所使用的硬件设备和相关软件)1、PC机 2、操作系统:Windows XP 3、软件:MyEclipse8.5, JDK1.6、Tomcat7.0,IE8三、实验内容及步骤必做题:调试课本第111页购物

2、车程序。选做题:修改Web程序设计实验五中的第一题,添加值JavaBean封装留言信息,添加工具JavaBean进行乱码处理,和一个字符转换JavaBean,将用户输入的回车和空格转换成能够在JSP页面中输出的回车和空格,即“”和“ ” 四、实验结果(本实验源程序清单及运行结果或实验结论、实验设计图)Index.jsp留 言 者:留言标题:留言内容:查看留言Show.jsp=0;i-)WordSingle single=(WordSingle)wordlist.get(i);%留 言 者:留言时间:留言标题:留言内容: 我要留言WordSingle.javapackage com.y

3、xq.valuebean;public class WordSingle private String author;private String title;private String content;private String time;public String getAuthor() return author;public void setAuthor(String author) this.author = author;public String getContent() return content;public void setContent(String content

4、) this.content = content;public String getTime() return time;public void setTime(String time) this.time = time;public String getTitle() return title;public void setTitle(String title) this.title = title;MyTools.javapackage com.yxq.toolbean;import java.io.UnsupportedEncodingException;import java.text

5、.SimpleDateFormat;import java.util.Date;public class MyTools public static String changeHTML(String source)String changeStr=;changeStr=source.replace(&,&);changeStr=changeStr.replace( , );changeStr=changeStr.replace(,>);changeStr=changeStr.replace(rn,);return changeStr;public static Stri

6、ng changeTime(Date date) SimpleDateFormat format=new SimpleDateFormat(yyyy-MM-dd HH:mm:ss);return format.format(date); public static String toChinese(String str) if(str=null)str=;try str=new String(str.getBytes(ISO-8859-1),gb2312); catch (UnsupportedEncodingException e) str=;e.printStackTrace();retu

7、rn str;WordServlet.javapackage com.yxq.servlet;import java.io.IOException;import java.util.ArrayList;import java.util.Date;import javax.servlet.ServletContext;import javax.servlet.ServletException;import javax.servlet.http.HttpServlet;import javax.servlet.http.HttpServletRequest;import javax.servlet

8、.http.HttpServletResponse;import javax.servlet.http.HttpSession;import com.yxq.toolbean.MyTools;import com.yxq.valuebean.WordSingle;public class WordServlet extends HttpServlet protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException doPost(

9、request,response);protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException String author=MyTools.toChinese(request.getParameter(author);String title=MyTools.toChinese(request.getParameter(title);String content=MyTools.toChinese(request.getP

10、arameter(content);String today=MyTools.changeTime(new Date();WordSingle single=new WordSingle();single.setAuthor(MyTools.changeHTML(author);single.setTitle(MyTools.changeHTML(title);single.setContent(content);single.setTime(today);HttpSession session=request.getSession();ServletContext scx=session.getServletContext();ArrayList wordlist=(ArrayList)scx.getAttribute(wordlist);if(wordlist=null)wordlist=new ArrayList();wordlist.add(single);scx.setAttribute(wordlist,wordlist);response.sendRedirect(show.jsp);五、实验总结(对本实验结果进行分析,实验心得体会及改进意见)实验评语实验成绩指导教师签名: 年 月 日

展开阅读全文
相关资源
相关搜索

当前位置:首页 > 建筑/环境 > 施工组织

电脑版 |金锄头文库版权所有
经营许可证:蜀ICP备13022795号 | 川公网安备 51140202000112号