- 1.25 MB
- 2022-04-22 11:32:28 发布
- 1、本文档共5页,可阅读全部内容。
- 2、本文档内容版权归属内容提供方,所产生的收益全部归内容提供方所有。如果您对本文有版权争议,可选择认领,认领后既往收益都归您。
- 3、本文档由用户上传,本站不保证质量和数量令人满意,可能有诸多瑕疵,付费之前,请仔细先通过免费阅读内容等途径辨别内容交易风险。如存在严重挂羊头卖狗肉之情形,可联系本站下载客服投诉处理。
- 文档侵权举报电话:19940600175。
'欢迎光临阳光大学生网,提供最全面的大学生课后习题答案和复习试题免费下载,http://www.sundxs.com/阳光大学生网我们希望呵护您的眼睛,关注您的成长,给您一片绿色的环境,欢迎加入我们,一起分享大学里的学习和生活感悟,免费提供:大学生课后答案,大学考试题及答案,大学生励志书籍。
(第二版)清华大学出版社(耿祥义张跃平编著)程序源代码I
摘要JSP是一种动态网页技术标准,利用这一技术可以建立安全、跨平台的先进动态网站。本书是一本实用教程,配备了大量的例题,叙述详细,通俗易懂,便于自学,特别注重结合实例讲解一些难点和关键技术。全书共分10章,内容包括JSP简介、JSP语法、内置对象、JSP与Javabean、文件操作、数据库操作、JavaServlet、MVC设计模式、JSP中使用XML等重要内容。本书所有知识都结合具体实例进行介绍.力求详略得当,突出JSP在开发Web动态网站方面的强大功能,使读者快速掌握和运用JSP的编程技巧。本书不仅可以作为大学计算机及相关专业的选修课教材,也适合自学者及网站开发人员参考使用。课后答案网II
课后答案网:www.hackshp.cn前言本书是《JSP实用教程》的第二版,继续保留原教材的特点——注重教材的可读性和实用性,许多例题都经过精心的考虑,即能帮助理解知识,同时又具有启发性。在第二版中增加了XML和MVC模式在Web设计中的应用,对全书章节的先后顺序和部分例题的内容做了调整。第1章介绍JSP重要性,对Tomcat服务器的安装与配置给予了详细介绍。第2章讲解JSP页面的基本构成、常用的JSP标记。第3章讲解内置对象,特别强调了这些内置对象在JSP应用开发中的重要性,结合实例使读者掌握内置对象的用法。第4章是JSP技术中很重要的内容,即怎样使用Javabean分离数据的显示和处理,这一章讲解了许多有一定应用价值的例子。第5章主要讲解怎样使用Java中的输入输出流实现文件的读写操作,在实例上特别强调怎样使用Javabean实现文件的读写操作。第6章涉及的内容是数据库,也是Web应用开发的非常重要的一部分内容,特别介绍了各种数据库的连接方式。第7章讲解JavaServlet,对servlet对象的运行原理给予了细致的讲解,许多例子都是大多数Web开发中经常使用的模块。在第8章对JavaServlet在MVC开发模式中的地位给予了重点介绍,并按着MVC模式给出了易于理解MVC设计模式的例子。第9章介绍了XML语言以及在JSP中怎样有效地使用XML文件。第10章是一个完整的网站,完全按着MVC模式开发设计,其目的是掌握一般Web应用中常用基本模块的开发方法。作者简介耿祥义,1995年中国科学技术大学博士毕业,获理学博士学位。1997年从中山大学博士后流动站出站。现任大连交通大学教授。已编写出版《Java2实用教程》、《Java课程设计》、《JSP实用教程》、《JSP基础教程》、《XML基础教程》等10余部教材。张跃平,现任大连交通大学讲师。已编写和参编出版《课后答案网VisualFoxPro课程设计》、《Java2实用教程》、《JSP实用教程》3部教材。希望本教材能对读者学习JSP有所帮助,并请读者批评指正(xygeng0629@sina.com)。编者2007年05月www.hackshp.cnIII若侵犯了您的版权利益,敬请来信告知!www.hackshp.cn
课后答案网:www.hackshp.cn第1章JSP简介........................................................................................................................................................................................................................................................11例子11................................................................................................................................................................................................................................................................................................................................................................................................................................................11第2章JSP语法..........................................................................................................................................................................................................................................................22例子1..............................................................................................................................................................................................................................................................................................22<%@pagecontentType="text/html;charset=GB2312"%>..............................22<%date=newDate();//java程序片..................................................................................22<%=start%>......................................................22例子2..............................................................................................................................................................................................................................................................................................22例子33................................................................................................................................................................................................................................................................................................................................................................................................................................................33例子44................................................................................................................................................................................................................................................................................................................................................................................................................................................33例子55................................................................................................................................................................................................................................................................................................................................................................................................................................................44例子66................................................................................................................................................................................................................................................................................................................................................................................................................................................44例子77................................................................................................................................................................................................................................................................................................................................................................................................................................................55例子88................................................................................................................................................................................................................................................................................................................................................................................................................................................55例子99................................................................................................................................................................................................................................................................................................................................................................................................................................................66例子1010.............................................................................................................................................................................................................................................................................................................................................................................................................................................77例子11..............................................................................................................................................................................................................................................................................................7课后答案网7例子1212.............................................................................................................................................................................................................................................................................................................................................................................................................................................88例子1313.............................................................................................................................................................................................................................................................................................................................................................................................................................................99第3章JSP内置对象....................................................................................................................................................................................................................................10www.hackshp.cn10例子11.............................................................................................................................................................................................................................................................................................................................................................................................................................................1010例子22.............................................................................................................................................................................................................................................................................................................................................................................................................................................1010例子33..............................................................................................................................................................................................................................................................................................11例子44.............................................................................................................................................................................................................................................................................................................................................................................................................................................1212例子55.............................................................................................................................................................................................................................................................................................................................................................................................................................................1414例子66.............................................................................................................................................................................................................................................................................................................................................................................................................................................1515例子77.............................................................................................................................................................................................................................................................................................................................................................................................................................................1616I若侵犯了您的版权利益,敬请来信告知!www.hackshp.cn
课后答案网:www.hackshp.cn例子88.............................................................................................................................................................................................................................................................................................................................................................................................................................................1717例子9............................................................................................................................................................................................................................................................................................1717例子10..........................................................................................................................................................................................................................................................................................1818例子11..........................................................................................................................................................................................................................................................................................1818例子12..........................................................................................................................................................................................................................................................................................1919例子13..........................................................................................................................................................................................................................................................................................2020例子1414.......................................................................................................................................................................................................................................................................................................................................................................................................................................2121例子15..........................................................................................................................................................................................................................................................................................2222例子1616.......................................................................................................................................................................................................................................................................................................................................................................................................................................2424例子1717.......................................................................................................................................................................................................................................................................................................................................................................................................................................2525例子18..........................................................................................................................................................................................................................................................................................2727例子19..........................................................................................................................................................................................................................................................................................2929第4章JSP与JavaBean............................................................................................................................................................................................................................3131Circle.javaCircle.java.....................................................................................................................................................................................................................................................................................................................................................................................................................3131例子1............................................................................................................................................................................................................................................................................................3131例子22.............................................................................................................................................................................................................................................................................................................................................................................................................................................3232例子33.............................................................................................................................................................................................................................................................................................................................................................................................................................................32课后答案网32NewCircle.javaNewCircle.java.............................................................................................................................................................................................................................................................................................................................................................................................3232例子44.............................................................................................................................................................................................................................................................................................................................................................................................................................................3333Student.javaStudent.java............................................................................................................................................................................................................................................................................................................................................................................................................3333例子55.............................................................................................................................................................................................................................................................................................................................................................................................................................................34www.hackshp.cn34Goods.javaGoods.java..................................................................................................................................................................................................................................................................................................................................................................................................................3434例子6............................................................................................................................................................................................................................................................................................3535ListFile.javaListFile.java............................................................................................................................................................................................................................................................................................................................................................................................................3636例子77.............................................................................................................................................................................................................................................................................................................................................................................................................................................3636三角形bean..........................................................................................................................................................................................................................................................................3737Triangle.javaTriangle.java........................................................................................................................................................................................................................................................................................................................................................................................................................3737四则运算bean..................................................................................................................................................................................................................................................................3838II若侵犯了您的版权利益,敬请来信告知!www.hackshp.cn
课后答案网:www.hackshp.cnComputerBean.java......................................................................................................................38computer.jsp.................................................................................................................................40计数器bean..........................................................................................................................................................................................................................................................................4040CounterCount.java.......................................................................................................................40comeOne.jsp.................................................................................................................................42comeTwo.jsp................................................................................................................................42浏览图像bean................................................................................................................................................................................................................................................................4242Play.java.......................................................................................................................................42play.jsp.........................................................................................................................................43成绩单bean........................................................................................................................................................................................................................................................................4444ScoreList.java...............................................................................................................................44studentScore.jsp...........................................................................................................................45日历bean..................................................................................................................................................................................................................................................................................4646CalendarBean.java.......................................................................................................................46showCalendar.jsp.........................................................................................................................48第5章JSP中的文件操作......................................................................................................................................................................................................................4949例子11.............................................................................................................................................................................................................................................................................................................................................................................................................................................4949FileDir.java...................................................................................................................................49fileAndDir.jsp...............................................................................................................................50例子22.............................................................................................................................................................................................................................................................................................................................................................................................................................................5050ReadFile.java...............................................................................................................................50课后答案网selectDir.jsp..................................................................................................................................52listfile.jsp......................................................................................................................................52例子33.............................................................................................................................................................................................................................................................................................................................................................................................................................................5353WriterFile.java.............................................................................................................................53www.hackshp.cnwritefile.jsp..................................................................................................................................54例子44.............................................................................................................................................................................................................................................................................................................................................................................................................................................5555UpFile.java................................................................................................................................55upfile.jsp.......................................................................................................................................58show.jsp......................................................................................................................................58例子55.............................................................................................................................................................................................................................................................................................................................................................................................................................................5858DownLoadFile.java......................................................................................................................58downfile.jsp..................................................................................................................................59例子66.............................................................................................................................................................................................................................................................................................................................................................................................................................................6060III若侵犯了您的版权利益,敬请来信告知!www.hackshp.cn
课后答案网:www.hackshp.cnReadByRow.java..........................................................................................................................60selectfile.jsp.................................................................................................................................61readByRow.jsp.............................................................................................................................62例子77.............................................................................................................................................................................................................................................................................................................................................................................................................................................6262Test.java....................................................................................................................................62test.jsp..........................................................................................................................................65第6章JSP中使用数据库......................................................................................................................................................................................................................6767例子11.............................................................................................................................................................................................................................................................................................................................................................................................................................................6767showByJdbcOdbc.jsp...................................................................................................................67例子2............................................................................................................................................................................................................................................................................................6868showBySQLDriver.jsp................................................................................................................68例子3............................................................................................................................................................................................................................................................................................6969QueryBean.java..........................................................................................................................69inquire.jsp.....................................................................................................................................71例子4............................................................................................................................................................................................................................................................................................7272RandomQueryBean.java..............................................................................................................72random.jsp..................................................................................................................................74例子5............................................................................................................................................................................................................................................................................................7575ConditionQuery.java................................................................................................................75condition.jsp............................................................................................................................77课后答案网例子6............................................................................................................................................................................................................................................................................................7878OrderQuery.java...........................................................................................................................78sort.jsp..........................................................................................................................................79例子7............................................................................................................................................................................................................................................................................................8080KeyWordQuery.java....................................................................................................................80www.hackshp.cnkeyWord.jsp................................................................................................................................82例子8............................................................................................................................................................................................................................................................................................8282AddBean.java..............................................................................................................................82add.jsp........................................................................................................................................84例子9............................................................................................................................................................................................................................................................................................8585ShowRecordByPage.java............................................................................................................85showByPage.jsp..........................................................................................................................88例子10..........................................................................................................................................................................................................................................................................................8989linkOracle.jsp..........................................................................................................................89IV若侵犯了您的版权利益,敬请来信告知!www.hackshp.cn
课后答案网:www.hackshp.cn例子11..........................................................................................................................................................................................................................................................................................9090linkMySql.jsp............................................................................................................................90例子12..........................................................................................................................................................................................................................................................................................9191MySqlBean.java..........................................................................................................................91mysql.jsp....................................................................................................................................93例子13..........................................................................................................................................................................................................................................................................................9494inquireExcel.jsp............................................................................................................................94例子14..........................................................................................................................................................................................................................................................................................9595ApplicationCon.java................................................................................................................95UseConBean.java.........................................................................................................................96chaxun.jsp....................................................................................................................................97例子15..........................................................................................................................................................................................................................................................................................9898PreparedQueryBean.java..........................................................................................................98pre.jsp......................................................................................................................................100例子16......................................................................................................................................................................................................................................................................................100100AddRecordBean.java.................................................................................................................100addRecord.jsp..........................................................................................................................102第7章JavaServlet基础............................................................................................................................................................................................................................104104HelloBeijing.java:........................................................................................................................................................................................................................................104104web.xmlweb.xml...........................................................................................................................................................................................................................................................................................................................................................................................................................104课后答案网104例子1..........................................................................................................................................................................................................................................................................................105105giveRadius.jsp........................................................................................................................105Computer.java............................................................................................................................105例子2..........................................................................................................................................................................................................................................................................................106www.hackshp.cn106showLetter.jsp............................................................................................................................106ShowLetter.java......................................................................................................................106例子3..........................................................................................................................................................................................................................................................................................107107showPI.jsp................................................................................................................................107ComputerPI.java......................................................................................................................107例子4..........................................................................................................................................................................................................................................................................................108108method.jsp................................................................................................................................108GetSqare.java..........................................................................................................................108GetSquareOrCubic.java..........................................................................................................109V若侵犯了您的版权利益,敬请来信告知!www.hackshp.cn
课后答案网:www.hackshp.cn例子5.............................................................................................................................................111input.jsp..................................................................................................................................111Verify.java..............................................................................................................................111ShowMessage.java.....................................................................................................................112例子6..........................................................................................................................................................................................................................................................................................113113Boy.java....................................................................................................................................113Look.java..................................................................................................................................114例子7..........................................................................................................................................................................................................................................................................................115115getLetter.jsp................................................................................................................................115inputLetter.jsp.............................................................................................................................115HandleGuess.java.......................................................................................................................116第8章基于Servlet的MVC模式....................................................................................................................................................................................................118118web.xml....................................................................................................................................................................................................................................................................................118118sun.yourservlet.HandleSum sun.yourservlet.HandleSum ....................................................................................................................................................................................118118Series.java....................................................................................................................................................................................................................................................................118118inputMess.jspinputMess.jsp................................................................................................................................................................................................................................................................................................................................................................................................119119showResult.jsp........................................................................................................................................................................................................................................................120120HandleSum.java........................................................................................................................................................................................................................................................120120计算一元二次方程的根................................................................................................................................................................................................................................122课后答案网122Equation.java..............................................................................................................................122input.jsp......................................................................................................................................123show.jsp......................................................................................................................................123HandleData.java.........................................................................................................................124简单的计算器................................................................................................................................................................................................................................................................125www.hackshp.cn125ComputerBean.java....................................................................................................................125inputNumber.jsp.........................................................................................................................126showResult.jsp...........................................................................................................................126HandleComputer.java.................................................................................................................127读取文件................................................................................................................................................................................................................................................................................129129FileMessage.java........................................................................................................................129choiceFile.jsp.............................................................................................................................129showFile.jsp...............................................................................................................................130HandleFile.java..........................................................................................................................130VI若侵犯了您的版权利益,敬请来信告知!www.hackshp.cn
课后答案网:www.hackshp.cn查询数据库........................................................................................................................................................................................................................................................................131131ShowRecordByPage.java...........................................................................................................131choiceDatabase.jsp.....................................................................................................................133showRecord.jsp..........................................................................................................................133HandleDatabase.java..................................................................................................................134第9章JSP中使用XML........................................................................................................................................................................................................................................139139例子11.......................................................................................................................................................................................................................................................................................................................................................................................................................................139139Score.xml..................................................................................................................................139input.jsp......................................................................................................................................140Number.java..............................................................................................................................140例子22.......................................................................................................................................................................................................................................................................................................................................................................................................................................142142trainList.xml...............................................................................................................................142train.jsp.......................................................................................................................................143SAXBean.java............................................................................................................................144例子33.......................................................................................................................................................................................................................................................................................................................................................................................................................................147147type.jsp....................................................................................................................................147formula.xml................................................................................................................................147show.css....................................................................................................................................148第10章基于会员制的网络广告系统........................................................................................................................................................................................150150head.txt................................................................................................................................................................................................................................................................................150150index.jsp............................................................................................................................................................................................................................................................................150课后答案网150web.xmlweb.xml...........................................................................................................................................................................................................................................................................................................................................................................................................................150150Register.javaRegister.java...................................................................................................................................................................................................................................................................................................................................................................................................152152register.jspregister.jsp...............................................................................................................................................................................................................................................................................................................................................................................................................153www.hackshp.cn153showRegisterMess.jspshowRegisterMess.jsp......................................................................................................................................................................................................................................................................................................................................................154154HandleRegister.javaHandleRegister.java...............................................................................................................................................................................................................................................................................................................................................................155155RequestDispatcherdispatcher=....................................................................................................................................................................................................157157Login.java........................................................................................................................................................................................................................................................................157157login.jsplogin.jsp...........................................................................................................................................................................................................................................................................................................................................................................................................................158158showLoginMess.jspshowLoginMess.jsp..................................................................................................................................................................................................................................................................................................................................................................158158HandleLogin.javaHandleLogin.java...........................................................................................................................................................................................................................................................................................................................................................................159159UploadFile.javaUploadFile.java....................................................................................................................................................................................................................................................................................................................................................................................161161VII若侵犯了您的版权利益,敬请来信告知!www.hackshp.cn
课后答案网:www.hackshp.cnupload.jspupload.jsp..................................................................................................................................................................................................................................................................................................................................................................................................................162162showUploadMess.jsp........................................................................................................................................................................................................................................162162HandleUpload.java............................................................................................................................................................................................................................................163163MemberInform.java............................................................................................................................................................................................................................................167167ShowByPage.javaShowByPage.java...........................................................................................................................................................................................................................................................................................................................................................................168168choiceLookType.jsp........................................................................................................................................................................................................................................169169
分页显示全体会员........................................................................................................................................................................................................................................169169showAllMember.jsp............................................................................................................................................................................................................................................169169showLookedMember.jsp................................................................................................................................................................................................................................170170HandleDatabase.java....................................................................................................................................................................................................................................171171Password.java............................................................................................................................................................................................................................................................175175modifyPassword.jspmodifyPassword.jsp...............................................................................................................................................................................................................................................................................................................................................................175175showNewPasswor.jsp........................................................................................................................................................................................................................................176176HandlePassword.javaHandlePassword.java......................................................................................................................................................................................................................................................................................................................................................176176RequestDispatcherdispatcher=....................................................................................................................................................................................................177177ModifyMessage.javaModifyMessage.java............................................................................................................................................................................................................................................................................................................................................................178178choiceModifyMess.jspchoiceModifyMess.jsp......................................................................................................................................................................................................................................................................................................................................................179课后答案网179inputModifyMess.jspinputModifyMess.jsp.........................................................................................................................................................................................................................................................................................................................................................179179GetOldMess.javaGetOldMess.java..............................................................................................................................................................................................................................................................................................................................................................................180180RequestDispatcherdispatcher=....................................................................................................................................................................................................182182HandleModifyMess.javaHandleModifyMess.java..........................................................................................................................................................................................................................................................................................................................................182www.hackshp.cn182RequestDispatcherdispatcher=....................................................................................................................................................................................................184184HandleExit.javaHandleExit.java....................................................................................................................................................................................................................................................................................................................................................................................184184VIII若侵犯了您的版权利益,敬请来信告知!www.hackshp.cn 课后答案网:www.hackshp.cn第1章JSP简介例子1eexample1_1.jspxample1_1.jsp<%@pagecontentType="text/html;charset=GB2312"%>1到100的连续和是:<%=sum%>
分页显示全体会员........................................................................................................................................................................................................................................169169showAllMember.jsp............................................................................................................................................................................................................................................169169showLookedMember.jsp................................................................................................................................................................................................................................170170HandleDatabase.java....................................................................................................................................................................................................................................171171Password.java............................................................................................................................................................................................................................................................175175modifyPassword.jspmodifyPassword.jsp...............................................................................................................................................................................................................................................................................................................................................................175175showNewPasswor.jsp........................................................................................................................................................................................................................................176176HandlePassword.javaHandlePassword.java......................................................................................................................................................................................................................................................................................................................................................176176RequestDispatcherdispatcher=....................................................................................................................................................................................................177177ModifyMessage.javaModifyMessage.java............................................................................................................................................................................................................................................................................................................................................................178178choiceModifyMess.jspchoiceModifyMess.jsp......................................................................................................................................................................................................................................................................................................................................................179课后答案网179inputModifyMess.jspinputModifyMess.jsp.........................................................................................................................................................................................................................................................................................................................................................179179GetOldMess.javaGetOldMess.java..............................................................................................................................................................................................................................................................................................................................................................................180180RequestDispatcherdispatcher=....................................................................................................................................................................................................182182HandleModifyMess.javaHandleModifyMess.java..........................................................................................................................................................................................................................................................................................................................................182www.hackshp.cn182RequestDispatcherdispatcher=....................................................................................................................................................................................................184184HandleExit.javaHandleExit.java....................................................................................................................................................................................................................................................................................................................................................................................184184VIII若侵犯了您的版权利益,敬请来信告知!www.hackshp.cn 课后答案网:www.hackshp.cn第1章JSP简介例子1eexample1_1.jspxample1_1.jsp<%@pagecontentType="text/html;charset=GB2312"%>
这是一个简单的JSP页面
<%inti,sum=0;for(i=1;i<=100;i++){sum=sum+i;}%>1到100的连续和是:<%=sum%>课后答案网www.hackshp.cn1若侵犯了您的版权利益,敬请来信告知!www.hackshp.cn
课后答案网:www.hackshp.cn第2章JSP语法例子1example2_1.jsp<%@pagecontentType="text/html;charset=GB2312"%><%@pageimport="java.util.Date"%><%!Datedate;//数据声明intstart,end,sum;publicintcontinueSum(intstart,intend)//方法声明{for(inti=start;i<=end;i++)sum=sum+i;returnsum;}%>程序片创建Date对象:<%date=newDate();//java程序片out.println("
"+date);start=1;end=100;sum=continueSum(start,end);%>课后答案网
从<%=start%>至<%=end%>的连续和是www.hackshp.cn<%=sum%>例子2eexample2_2.jspxample2_2.jsp:<%@pagecontentType="text/html;charset=GB2312"%><%!inti=0;%><%i++;%>2若侵犯了您的版权利益,敬请来信告知!www.hackshp.cn
课后答案网:www.hackshp.cn您是第<%=i%>个访问本站的客户。
程序片创建Date对象:<%date=newDate();//java程序片out.println(" 您是第<%=i%>个访问本站的客户。
"+date);start=1;end=100;sum=continueSum(start,end);%>课后答案网
从<%=start%>至<%=end%>的连续和是www.hackshp.cn<%=sum%>例子2eexample2_2.jspxample2_2.jsp:<%@pagecontentType="text/html;charset=GB2312"%>