JSP程序设计实验报告

上传人:风*** 文档编号:69988239 上传时间:2022-04-06 格式:DOC 页数:36 大小:494KB
收藏 版权申诉 举报 下载
JSP程序设计实验报告_第1页
第1页 / 共36页
JSP程序设计实验报告_第2页
第2页 / 共36页
JSP程序设计实验报告_第3页
第3页 / 共36页
资源描述:

《JSP程序设计实验报告》由会员分享,可在线阅读,更多相关《JSP程序设计实验报告(36页珍藏版)》请在装配图网上搜索。

1、精选优质文档-倾情为你奉上长江职业学院JSP语言程序设计实验指导书专 业: 学 号: 姓 名: 班 级: 指导 老师: 软件教研室 编目录l 实验一 .l 实验二 .l 实验三 .l 实验四 .l 实验五 .l 实验六 .l 实验七 . 实验一 Web编程环境一、 实验目的1. 搭建Web编程环境,能正确安装配置java运行环境、WEB服务器和数据库服务器2. 熟悉WEB编程集成环境MYEclipse.3. 熟练掌握WEB工程的创建、发布、运行流程。二、 实验内容1. 安装并配置java运行环境JDK和JRE2. 安装Web服务器tomcat, 配置Tomcat服务器3. 安装并配置数据库My

2、SQL.4. 安装MyEclispe,熟悉各项菜单项5. 为MyEclispe集成配置JDK和Tomcat6. 创建、发布、运行一个WEB工程。三、 实验仪器及耗材计算机,JDK,TOMCAT, MySQL, MyEclipse等软件。四、 实验步骤1、 安装并配置JDK和JRE2、 设置好classpath和path路径3、 安装Tomcat5.54、 设置Tomcat的配置属性5、 安装并配置MySQL数据库6、 安装MySqL Administrator工具7、 安装MyEclipse8、 新建并配置一个工程,运行发布一个新的工程。五、 实验结果1、 JDK、JRE安装结果:2、 Cla

3、sspath和path设置3、 安装并配置Tomcat4、 安装并配置MySqL和MySqL Administrator 工具5、 安装MyEclipse6、 发布一个Web工程。六、 实验心得实验二 HTML和CSS编程技术 一、 实验目的1. 熟悉HTML静态网页编程技术,熟悉HTML各种标记,特别是表单标记2. 熟悉CSS编程技术,掌握CSS来格式化网页、掌握CSS盒式模型3. 掌握DIV+CSS布局和设计网页,掌握CSS设计网页的一般流程4. 熟悉Dreamweaver的CSS设计器二、 实验内容1. 构思一个新闻发布网站,主题自选,设计好新闻类别2. 制作主页PSD图3. 用DIV+

4、CSS布局主页框架。(如可分成top, mid, foot, 其中mid再分两大块left和main)4. 分别细化设计每一大块。5. 要中间部分的左边或右边要设计一个小登录表单,并用CSS美化。三、 实验仪器及耗材计算机,Dreamweaver 8,Photoshop,MyEclipse等软件。四、 实验步骤1、 制作PSD图2、 使用DIV+CSS布局3、 细化每一块4、 美化表单部分五、 实验结果1、制作PSD图2、使用DIV+CSS布局3、细化每一块4、美化表单部分六、 实验心得实验三 JavaScript编程技术一、 实验目的1. 熟悉JavaScript语法2. 掌握JavaScr

5、ipt函数的创建和调用3. 熟悉JavaScript对象,特别是浏览器对象,了解DOM模型,知道文档对象的访问方法。4. 会用JavaScript来对表单进行验证。二、 实验内容1. 用JavaScript完成对登录表单的验证2. 设计一个新闻发布的页面,并用JavaScript对新闻发布表单进行验证。三、 实验仪器及耗材计算机,Dreamweaver 8,Photoshop,MyEclipse等软件。四、 实验步骤1、 设计和实现对表单验证的过程代码如下:function checklogin()var user=document.getElementsByName(username)0.v

6、alue;var pass=document.getElementsByName(password)0.value;if(user=)alert(请输入用户名);return false;else if(pass=)alert(请输入密码);return false;elsereturn true;2、 设计和实现对新闻发布的验证过程代码如下:function checkarticle()var a=document.getElementsByName(author)0.value;var t=document.getElementsByName(title)0.value;var c=doc

7、ument.getElementsByName(content)0.value;if(a=)alert(请输入的作者);return false;if(t=)alert(请输入的标题);return false;else if(c=)alert(请输入的内容);return false;else return true;五、 实验结果1、 表单验证结果2、 文章发布页面验证六、 实验心得实验四 Servlet编程技术一、 实验目的1. 熟悉Servlet技术的创建和运行流程。2. 会在web.xml配置Servlet的URL3. 熟悉请求request和响应response接口4. 熟悉请求转

8、发接口requestDispatcher接口5. 熟悉会话Session接口,掌握基于Session登录权限控制。二、 实验内容完成一个基于Session的登录权限控制模块。要求:a) 主页登录表单提交后转到Servlet进行处理,根据用户类型转到不同的页面。如果在用户名或密码不正确把登录表单包含进来b) 对于某些页面必须登录才能访问,如新闻发布页面。如果没有登录则禁止访问,并重定向到登录页面。三、 实验仪器及耗材计算机, MyEclipse等软件。四、 实验步骤1、 设计和实现一个登录表单2、 设计和实现实现验证的Servlet,然后进行验证五、 实验结果1、 表单验证效果2、 验证Serv

9、let源代码public class LoginServlet extends HttpServlet /* * Constructor of the object. */public LoginServlet() super();/* * Destruction of the servlet. */public void destroy() super.destroy(); / Just puts destroy string in log/ Put your code here/* * The doGet method of the servlet. * * This method is

10、called when a form has its tag value method equals to get. * * param request the request send by the client to the server * param response the response send by the server to the client * throws ServletException if an error occurred * throws IOException if an error occurred */public void doGet(HttpSe

11、rvletRequest request, HttpServletResponse response)throws ServletException, IOException response.setContentType(text/html);PrintWriter out = response.getWriter();out.println();out.println();out.println( A Servlet);out.println( );out.print( This is );out.print(this.getClass();out.println(, using the

12、GET method);out.println( );out.println();out.flush();out.close();/* * The doPost method of the servlet. * * This method is called when a form has its tag value method equals to post. * * param request the request send by the client to the server * param response the response send by the server to th

13、e client * throws ServletException if an error occurred * throws IOException if an error occurred */public void doPost(HttpServletRequest request, HttpServletResponse response)throws ServletException, IOException request.setCharacterEncoding(GBK);response.setContentType(text/html;charset=GBK);respon

14、se.setCharacterEncoding(GBK);String username=request.getParameter(username);System.out.println(用户名:+username);MemberProcess mp=new MemberProcess();if(mp.isExisted(username)String password=request.getParameter(password);System.out.println(输入的密码:+password);if(mp.validate(username,password)HttpSession

15、session=request.getSession(true);Member m=mp.getMemberByName(username);session.setAttribute(userinfo, m);session.setAttribute(login, true);session.setAttribute(memberId, username);session.setAttribute(loginusername, username);if(request.getParameter(backpage)=null)request.getRequestDispatcher(index.

16、jsp).forward(request, response);elserequest.getRequestDispatcher(request.getParameter(backpage).forward(request, response);elserequest.setAttribute(loginresult,密码错误);request.getRequestDispatcher(member.jsp).forward(request, response);elserequest.setAttribute(loginresult,用户名不存在);request.getRequestDis

17、patcher(login.jsp).forward(request, response);/* * Initialization of the servlet. * * throws ServletException if an error occurs */public void init() throws ServletException / Put your code here六、 实验心得实验五 JSP编程技术一、 实验目的6. 熟悉JSP编译指令,动作标记。7. 熟悉JSP的隐含对象8. 正确理解request、session、application三个对象的作用域9. 能正确处理

18、汉字乱码问题10. 能熟练使用JSP技术来编写网页二、 实验内容1. 编写一个文章类,用Myeclipse的工作自动产生getter和settet函数2. 修改前面编写过的管理员的新闻发布页面,改成JSP页面要求如下:1)撰写界面至少包括文件标题,所属栏目、作者、内容几项2)界面用CSS进行美化3)每个输入框均应有name属性。4)权限控制,必须是管理员用户才能访问,跟前面实验的登录权限控制关联起来。 3. 编写一个Servlet来处理新闻发布页面提交的表单要求:1)读取表单各项内容,并把存入一个文章对象中。2)把文章对象绑定在request对象中,并转发到新闻显示页面。3. 编写一个新闻显示

19、页面。 要求: 1) 编写静态页面模板,页面用div+css设计2)设定文章对象已存在request对象中,取出文章对象3)把静态页面的内容改成动态内容,如标题,作者,内容等。三、 实验仪器及耗材计算机,Dreamweaver 8,Photoshop,MyEclipse等软件。四、 实验步骤1、 设计和实现新闻发布系统的页面2、 、设计和实现后台的Servlet五、 实验结果1、 页面的实现2、 Servlet的实现public class ArticleServlet extends HttpServlet private static final long serialVersionUID

20、 = 1L;public ArticleServlet() super();public void destroy() super.destroy(); / Just puts destroy string in log/ Put your code here/* * The doGet method of the servlet. * * This method is called when a form has its tag value method equals to get. * * param request the request send by the client to th

21、e server * param response the response send by the server to the client * throws ServletException if an error occurred * throws IOException if an error occurred */public void doGet(HttpServletRequest request, HttpServletResponse response)throws ServletException, IOException request.setCharacterEncod

22、ing(GBK);response.setCharacterEncoding(GBK);response.setContentType(text/html;charset=GBK);ArticleBll ab=new ArticleBll();String opType=request.getParameter(opType);if(opType=null)request.getRequestDispatcher(articlelist.jsp).forward(request, response);else if(opType.equals(see)String aid=request.ge

23、tParameter(articleId);int id=0;try id=Integer.parseInt(aid);catch(NumberFormatException e)id=1;Article a=ab.getArticle(id);request.setAttribute(article, a);request.getRequestDispatcher(article.jsp).forward(request, response);else if(opType.equals(seecmts)String aid=request.getParameter(articleId);in

24、t id=0;try id=Integer.parseInt(aid);catch(NumberFormatException e)id=1; Vector cmts=ab.getComments(id);request.setAttribute(comments, cmts);request.getRequestDispatcher(allcomments.jsp?articleId=+id).forward(request, response);else if(opType.equals(remove)String aid=request.getParameter(articleId);i

25、nt id=0;try id=Integer.parseInt(aid);catch(NumberFormatException e)id=1; new ArticleBll().remove(id);request.getRequestDispatcher(article.jsp?articleId=+id).forward(request, response);/* * The doPost method of the servlet. * * This method is called when a form has its tag value method equals to post

26、. * * param request the request send by the client to the server * param response the response send by the server to the client * throws ServletException if an error occurred * throws IOException if an error occurred */public void doPost(HttpServletRequest request, HttpServletResponse response)throw

27、s ServletException, IOException request.setCharacterEncoding(GBK);response.setCharacterEncoding(GBK);response.setContentType(text/html;charset=GBK);String opType=request.getParameter(opType);if(opType=null)String aid=request.getParameter(articleId);int id=0;try id=Integer.parseInt(aid);catch(NumberF

28、ormatException e)id=1; request.getRequestDispatcher(article.jsp?articleId=+id).forward(request, response);else if(opType.equals(givecmt)/发表评论String aid=request.getParameter(articleId);int id=0;try id=Integer.parseInt(aid);catch(NumberFormatException e)id=1; Comment c=new Comment();c.setArticle_id(id

29、);c.setTitle(request.getParameter(title);c.setContent(request.getParameter(content);new CommentBll().insert(c);request.getRequestDispatcher(article.jsp?articleId=+id).forward(request, response);/* * Initialization of the servlet. * * throws ServletException if an error occurs */public void init() th

30、rows ServletException / Put your code here六、 实验心得实验六 JavaBean编程技术 一、 实验目的1. 熟悉JavaBean的规范2. 会编写JavaBean; 会在JSP和Servlet中创建和使用JavaBean对象3. 掌握JSP的、的使用4. 掌握JSP中表单和表单Bean的映射5. 掌握Servlet中表单和表单Bean的映射6. 会编写封装业绩逻辑的JavaBean7. 会使用上传下载组件jspSmartUpload外部组件二、 实验内容1. 修改前面的封装新闻(文章)的JavaBean,使其符合JavaBean规范2. 修改前面的新

31、闻发表Serlvet,用来完成新闻发布表单的处理,要求利用映射机制把新闻表单映射到新闻的JavaBean中,以便后继把这个JavaBean写入数据库。3. 编写一个封闭新闻管理的业务Bean. 这里只需定义接口即可。4. 参考教材,编写一个上传下载模块(可选)5. 参考教材,实现登录动态验证(可选)三、 实验仪器及耗材计算机,Dreamweaver 8,Photoshop,MyEclipse等软件。四、 实验步骤1、 编写文章Bean2、 编写业务Bean五、 实验结果1、 文章Bean源代码package article.entity;import java.sql.Date;public

32、class Article private int id;private String title;private String author;private String content;private Date created_time;private Date updated_time;public int getId() return id;public void setId(int id) this.id = id;public String getTitle() return title;public void setTitle(String title) this.title =

33、 title;public String getAuthor() return author;public void setAuthor(String author) this.author = author;public String getContent() return content;public void setContent(String content) this.content = content;public Date getCreated_time() return created_time;public void setCreated_time(Date created_

34、time) this.created_time = created_time;public Date getUpdated_time() return updated_time;public void setUpdated_time(Date updated_time) this.updated_time = updated_time;2、 业务Bean源代码public class AdminProcess public Administrator getAdminByName(String username) Administrator a=null;String sql=select *

35、 from admin where username=+username+;ResultSet rs=DBAccess.executeQueary(sql);if(rs!=null)try a=new Administrator();a.setId(rs.getInt(1);a.setUsername(rs.getString(2);a.setPassword(rs.getString(3);return a; catch (SQLException e) return null;return a;3、 数据库连接Bean的实现public class DBAccess private sta

36、tic String driver=com.mysql.jdbc.Driver;private static String dbUrl=jdbc:mysql:/localhost:3306/article_db;private static String user=root;private static String password=root;private static Connection conn=null;private static Statement stat=null;private static ResultSet rs=null;public static Connecti

37、on getConnection()try Class.forName(driver);conn=DriverManager.getConnection(dbUrl, user, password); catch (ClassNotFoundException e1) e1.printStackTrace();return null;catch (SQLException e) e.printStackTrace();return null;return conn;public static ResultSet executeQueary(String sql)System.out.print

38、ln(sql);conn=getConnection();try stat=conn.createStatement();rs=stat.executeQuery(sql); catch (SQLException e) e.printStackTrace();return null;try return rs.next()?rs:null; catch (SQLException e) System.out.println(DBAccess中发生了错误);e.printStackTrace();return null;public static int executeUpdate(Strin

39、g sql)System.out.println(DB update:+sql);conn=getConnection();int rows=0;try stat=conn.createStatement();rows=stat.executeUpdate(sql); catch (SQLException e) e.printStackTrace();return 0;return rows;public static void close()if(rs!=null)try rs.close(); catch (SQLException e) e.printStackTrace();if(s

40、tat!=null)try stat.close(); catch (SQLException e) e.printStackTrace();if(conn!=null)try conn.close(); catch (SQLException e) e.printStackTrace();六、 实验心得实验七 JDBC数据库编程技术 (4课时)一、 实验目的1. 掌握JDBC来访问数据库的一般步聚2. 掌握JDBC来连接各类数据库3. 掌握Connection、Statement、PrepareStatement和ResultSet几个类。4. 掌握JDBC事务处理机制。5. 会编写使用JD

41、BC访问数据库的JavaBean6. 掌握分页显示技术7. 掌握连接池技术二、 实验内容1. 创建一个数据库,创建用户信息表、新闻表(与前面的JavaBean对应,注意类型的选择)2. 创建一个访问数据库的JavaBean, 或把创建连接createConn(), 关闭连接closeConn()方法写到新闻管理业务Bean中。3. 实现新闻管理业务Bean中的各个模块,如登录验证、新闻发布、新闻列表、新闻阅读等数据库访问。4. 配置Tomcat自带的连接池,并修改访问数据库的Bean或新闻管理业务Bean中的创建连接方法createConn(),使之能调用连接池。5. 编写新闻阅读、新闻列表J

42、SP页面。三、 实验仪器及耗材计算机,Dreamweaver 8,MyEclipse等软件。四、 实验步骤1、 创建数据库2、 创建数据库连接的类3、 设计和实现各个模块的Javabean五、 实验结果1、 数据库2、 数据库连接类3、 设计和实现各个模块的Javabeanpublic class ArticleBll public Vector getPageOfArticles(int pageSize,int pageIndex,int increase)Vector as=new Vector();String sql=select * from article limit +(pag

43、eIndex-1)*pageSize+,+increase;ResultSet rs=DBAccess.executeQueary(sql);if(rs!=null)try doArticle a=new Article();a.setId(rs.getInt(1);a.setTitle(rs.getString(2);a.setAuthor(rs.getString(3);a.setContent(rs.getString(4);a.setCreated_time(rs.getDate(5);a.setUpdated_time(rs.getDate(6);as.add(a);while(rs

44、.next(); catch (SQLException e) return as;finallyDBAccess.close();return as;public Article getArticle(int id)Article a=new Article();String sql=select * from article where id=+id;ResultSet rs=DBAccess.executeQueary(sql);if(rs!=null)try doa.setId(rs.getInt(1);a.setTitle(rs.getString(2);a.setAuthor(rs

45、.getString(3);a.setContent(rs.getString(4);a.setCreated_time(rs.getDate(5);a.setUpdated_time(rs.getDate(6);while(rs.next(); catch (SQLException e) return a;finallyDBAccess.close();return a;public Vector getComments(int id)Vector as=new Vector();String sql=select * from comment where article_id=+id;R

46、esultSet rs=DBAccess.executeQueary(sql);if(rs!=null)try doComment a=new Comment();a.setId(rs.getInt(1);a.setArticle_id(rs.getInt(2);a.setContent(rs.getString(3);a.setCreated_time(rs.getDate(4);a.setTitle(rs.getString(5);as.add(a);while(rs.next(); catch (SQLException e) return as;finallyDBAccess.clos

47、e();return as;public void insert(Article a)String sql=insert into article(title,author,con +tent,created_time) values( +a.getTitle()+,+a.getAuthor()+,+a.getContent()+,now();DBAccess.executeUpdate(sql);DBAccess.close();public void remove(int id)String sql=delete from article where id=+id;DBAccess.exe

48、cuteUpdate(sql);DBAccess.close();/public void update(Article a)/String sql=delete from article where id=+id;/DBAccess.executeUpdate(sql);/DBAccess.close();/public void removeAllComments(int id)String sql=delete from article where article_id=+id;DBAccess.executeUpdate(sql);DBAccess.close();public int

49、 getArticlePageCount(int pageSize)String sql=select count(id) from article;int count=0;ResultSet rs=DBAccess.executeQueary(sql);if(rs!=null)try count=rs.getInt(1);int i=count%pageSize;count=i=0?count/pageSize:(count/pageSize+1); catch (SQLException e) return count;finallyDBAccess.close();return count;六、 实验心得专心-专注-专业

展开阅读全文
温馨提示:
1: 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
2: 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
3.本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
5. 装配图网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
关于我们 - 网站声明 - 网站地图 - 资源地图 - 友情链接 - 网站客服 - 联系我们

copyright@ 2023-2025  zhuangpeitu.com 装配图网版权所有   联系电话:18123376007

备案号:ICP2024067431-1 川公网安备51140202000466号


本站为文档C2C交易模式,即用户上传的文档直接被用户下载,本站只是中间服务平台,本站所有文档下载所得的收益归上传人(含作者)所有。装配图网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对上载内容本身不做任何修改或编辑。若文档所含内容侵犯了您的版权或隐私,请立即通知装配图网,我们立即给予删除!