JavaWeb编程技术(第2版)源代码.doc

上传人:laozhun 文档编号:2386817 上传时间:2023-02-17 格式:DOC 页数:90 大小:545KB
返回 下载 相关 举报
JavaWeb编程技术(第2版)源代码.doc_第1页
第1页 / 共90页
JavaWeb编程技术(第2版)源代码.doc_第2页
第2页 / 共90页
JavaWeb编程技术(第2版)源代码.doc_第3页
第3页 / 共90页
JavaWeb编程技术(第2版)源代码.doc_第4页
第4页 / 共90页
JavaWeb编程技术(第2版)源代码.doc_第5页
第5页 / 共90页
点击查看更多>>
资源描述

《JavaWeb编程技术(第2版)源代码.doc》由会员分享,可在线阅读,更多相关《JavaWeb编程技术(第2版)源代码.doc(90页珍藏版)》请在三一办公上搜索。

1、Java Web编程技术(第2版)沈泽刚 编著 清华大学出版社 2014.4作者E-mail地址:shenzegang shenzegang电 话:13050451166感谢您使用本书,为方便您使用本书中程序,下面是书中全部程序源代码。如有任何问题,希望联系作者。程序1.1 register.html用户注册用户注册姓名:年龄:性别:男 女兴趣:文学 体育 电脑学历: 学士 硕士 博士 邮件地址:程序1.2 index.html派派电子商城 用户名 密 码 商品分类 手机数码 家用电器 汽车用品 服饰鞋帽 运动健康 三星 S5830领取手机节优惠券,立减100元!再送:200元移动手机卡!派派

2、价:2068元 联想(Lenovo)G460AL-ITH 14.0英寸笔记本电脑(i3-370M 2G 500G 512独显 DVD刻录 摄像头 Win7)特价:3199元! Copyright © 2013 派派电子商城有限责任公司,8899123. 程序1.3 layout.cssbody font-family:Verdana; font-size:14px; margin:10;#container margin:0 auto; width:100%;#header height:50px; background:#9c6; margin-bottom:5px;#topmen

3、u height:30px; background:#c0c0c0; margin-bottom:5px;#middle margin-bottom:5px;#leftmenu float:left; width:180px; background:#cf9;#content float:left; background:#ffa;#footer height:60px; background:#9c6; clear:both;程序1.4 inputCheck.html用户注册 function custCheck() var custName = document.getElementByI

4、d(custName); var email = document.getElementById(email); var phone = document.getElementById(phone); if(custName.value=) alert(客户名不能为空!); return false; else if(email.value.indexOf()=-1) alert(电子邮件中应包含字符!); return false; else if(phone.value.length!=8) alert(电话号码应是8位数字!); return false; *,input font-si

5、ze:11pt;color:black请输入客户信息:客户名: Email地址: 电话: 程序1.5 HelloServlet.javapackage com.demo;import java.io.IOException;import javax.servlet.ServletException;import javax.servlet.annotation.WebServlet;import javax.servlet.http.HttpServlet;import javax.servlet.http.HttpServletRequest;import javax.servlet.htt

6、p.HttpServletResponse;import java.io.*;WebServlet(name = helloServlet, urlPatterns = /helloServlet.do )public class HelloServlet extends HttpServlet private static final long serialVersionUID = 1L;protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException,

7、 IOException response.setContentType(text/html;charset=UTF-8);PrintWriter out = response.getWriter(); out.println(); out.println(Hello Servlet); out.println(Hello,World!); out.println(现在的时间是:+new java.util.Date(); out.println(); out.println(); 程序1.6 hello.jsp简单的JSP页面Hello,World!现在的时间是:程序2.1 login.js

8、p登录页面 用户名: 密  码: 程序2.2 LoginServlet.javapackage com.demo;import java.io.*;import javax.servlet.*;import javax.servlet.http.*;import javax.servlet.annotation.WebServlet;WebServlet(name=LoginServlet,urlPatterns=/login.do)public class LoginServlet extends HttpServlet public void doPost(HttpSe

9、rvletRequest request, HttpServletResponse response) throws ServletException, IOException String username = request.getParameter(username);String password = request.getParameter(password); response.setContentType(text/html;charset=UTF-8); PrintWriter out = response.getWriter(); out.println(); if(admi

10、n.equals(username)& admin.equals(password) out.println(登录成功!欢迎您, +username); else out.println(对不起!您的用户名或密码不正确); out.println(); 程序2.3 ClientInfoServlet.javapackage com.demo;import java.io.*;import javax.servlet.*;import javax.servlet.http.*;import javax.servlet.annotation.WebServlet;WebServlet(/Clien

11、tInfoServlet)public class ClientInfoServlet extends HttpServlet public void doGet(HttpServletRequest request,HttpServletResponse response) throws ServletException, IOException response.setContentType(text/html;charset=UTF-8); PrintWriter out = response.getWriter(); out.println(); out.println(获取客户端信息

12、); out.println(); out.println(客户端信息:); out.println(); out.println(客户主机名); out.println( + request.getRemoteHost() + ); out.println(客户IP地址); out.println( + request.getRemoteAddr() + ); out.println(端口); out.println( + request.getRemotePort() + ); out.println(请求方法); out.println( + request.getMethod() +

13、); out.println(请求协议); out.println( + request.getProtocol() + ); out.println(请求URI); out.println( + request.getRequestURI() + ); out.println(); out.println();public void doPost(HttpServletRequest request,HttpServletResponse response) throws ServletException, IOException doGet(request, response); 程序2.

14、4 ShowHeadersServlet.javapackage com.demo;import java.io.*;import javax.servlet.*;import javax.servlet.http.*;import java.util.Enumeration;import javax.servlet.annotation.WebServlet; WebServlet(/ShowHeaders)public class ShowHeadersServlet extends HttpServletpublic void doGet(HttpServletRequest reque

15、st, HttpServletResponse response)throws ServletException, IOException response.setContentType(text/html;charset=UTF-8);PrintWriter out = response.getWriter();out.println();out.println(请求头信息);out.println(服务器收到的请求头信息); out.println(request.getMethod()+ +request.getRequestURI()+ +request.getQueryString(

16、)+ +request.getProtocol()+);Enumeration headers = request.getHeaderNames();while(headers.hasMoreElements()String header = (String) headers.nextElement();String value = request.getHeader(header);out.println(header+ = +value+);out.println();程序2.5 LoginServlet.javapackage com.demo;import java.io.*;impo

17、rt javax.servlet.*;import javax.servlet.http.*;import javax.servlet.annotation.WebServlet;WebServlet(name=LoginServlet,urlPatterns=/login.do)public class LoginServlet extends HttpServlet public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException

18、 String username = request.getParameter(username); String password = request.getParameter(password); / 用户名和口令均为admin,认为登录成功 if(username.equals(admin)&password.equals(admin) request.setAttribute(username, username); RequestDispatcher rd = request.getRequestDispatcher(/welcome.jsp); rd.forward(request

19、, response); else RequestDispatcher rd = request.getRequestDispatcher(/login.jsp); rd.forward(request, response); 程序2.6 welcome.jspYour are welcome!$username程序2.7 questions.jsp简单测试请回答下面的问题: 1. Sun公司于2010年被Oracle公司收购。 正确 错误 2. Windows操作系统是哪个公司的产品? Apple公司 IBM公司 Microsoft公司 3.下面的程序设计语言,哪些是面向对象的? Java语

20、言 C语言 C+语言 4.编写Servlet程序应继承哪个类?交卷请点击:重答请点击: 程序2.8 SimpleTestServlet.javapackage com.demo;import java.io.IOException;import java.io.PrintWriter;import javax.servlet.ServletException;import javax.servlet.annotation.WebServlet;import javax.servlet.http.HttpServlet;import javax.servlet.http.HttpServletR

21、equest;import javax.servlet.http.HttpServletResponse;WebServlet(name=SimpleTestServlet,urlPatterns=/simpletest.do)public class SimpleTestServlet extends HttpServlet private static final long serialVersionUID = 1L; protected void doPost(HttpServletRequest request, HttpServletResponse response) throws

22、 ServletException, IOException response.setContentType(text/html;charset=UTF-8); PrintWriter out = response.getWriter(); String quest1 = request.getParameter(quest1); String quest2 = request.getParameter(quest2); String quest3 = request.getParameterValues(quest3); String quest4 = request.getParamete

23、r(quest4).trim();int score = 0;if(quest1!=null & quest1.equals(1) score = score+25; / 答对一道题加25分if(quest2!=null& quest2.equals(3) score = score+25;if(quest3!=null&quest3.length=2&quest30.equals(1)& quest31.equals(3) score = score+25;if(quest4!=null& (quest4.equals(HttpServlet)|quest4.equals(javax.ser

24、vlet.http.HttpServlet) score = score+25;out.println();out.println(测试结果);out.println();out.println(你的成绩是:+score+分);out.println(); 程序2.9 fileUpload.jsp上传文件$message 文件上传 会员号: 文件名: 程序2.10 FileUploadServlet.javapackage com.demo;import java.io.*;import javax.servlet.*;import javax.servlet.http.*;import ja

25、vax.servlet.annotation.*;WebServlet(name=FileUploadServlet,urlPatterns=/fileUpload.do)MultipartConfig(location=D:,fileSizeThreshold=1024)public class FileUploadServlet extends HttpServletpublic void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException,IOException/ 返回Web应用程序文档根目录String path = this.getServletContext().getRealPath(/); String mnumber = request.getParameter(mnumber);Part p = re

展开阅读全文
相关资源
猜你喜欢
相关搜索

当前位置:首页 > 建筑/施工/环境 > 项目建议


备案号:宁ICP备20000045号-2

经营许可证:宁B2-20210002

宁公网安备 64010402000987号