java ee_4(简单的用户登录网站)

上传人:第*** 文档编号:54455940 上传时间:2018-09-13 格式:PPT 页数:36 大小:1.42MB
返回 下载 相关 举报
java ee_4(简单的用户登录网站)_第1页
第1页 / 共36页
java ee_4(简单的用户登录网站)_第2页
第2页 / 共36页
java ee_4(简单的用户登录网站)_第3页
第3页 / 共36页
java ee_4(简单的用户登录网站)_第4页
第4页 / 共36页
java ee_4(简单的用户登录网站)_第5页
第5页 / 共36页
点击查看更多>>
资源描述

《java ee_4(简单的用户登录网站)》由会员分享,可在线阅读,更多相关《java ee_4(简单的用户登录网站)(36页珍藏版)》请在金锄头文库上搜索。

1、一个简单的用户登录网站,软件学院 代飞 2012.春,简单的用户登录网站(Servlet版-loginV1),要求:使用HttpServlet开发; 基本功能: 1、进行简单的用户验证; 知识点: 1、如何使用servlet开发动态网页; 2、如何从一个页面跳转到另外一个页面;,loginV1的框架图,Login.java 登录界面,LoginCheck.java 验证用户登录,Welcome.java 欢迎界面,登录请求,合法用户,用户不合法,配置eclipse开发WEB应用,1、配置tomcat server; 2、新建Dynamic web project; 3、调整web projec

2、t结构,加入servlet-api; 4、开发Login.java; 5、配置web.xml; 6、配置虚拟目录(confserver.xml);,配置Tomcat server,配置web.xml,logincn.edu.ynu.loginV1.Loginlogin/login.do,配置虚拟目录,清单目录,Login.java LoginCheck.java Welcome.java web.xml server.xml,HttpServletRequest,The HTTP Request Method Determines whether doGet() or doPost() run

3、s,The clients request always includes a specific HTTP Method. If the HTTP Method is a GET, the service() method calls doGet(). If the HTTP request Method is a POST, the service() method calls doPost().,HttpServletRequest,String name =request.getParameter(“username”) String sizes= request.getParamete

4、rs(“sizes”) String client =request.getHeader(“User-Agent”) String cookies = request.getCookies() Session session = request.getSession(),Sending and Using a single Parameter,Sending and Using a single Parameter,Sending and Using a single Parameter,Sending and Using TWO Parameters,Sending and Using TW

5、O Parameters,Sending and Using TWO Parameters,Sending and Using Multiple Values for a Parameter,Sending and Using Multiple Values for a Parameter,HttpServletResponse,HttpServletResponse,Most of the time, you use the Response just to send data back to the client. Generally, you use the response objec

6、t to get an output stream (usually a Writer) and you use that stream to write the HTML (or some other type of content) that goes back to the client.,HttpServletResponse,response.setContentType(“text/html;charset=gbk“); PrintWriter out = response.getWriter(); out.println(“hello, world!“); response.se

7、ndRedirect(“login.do“);,Common MIME types,text/html application/pdf video/quicktime application/java image/jpeg application/jar application/octet-stream application/x-zip,Two Choices for Output: Characters or Bytes,HttpServletResponse is just plain old java.io, except two streams : ServletOutputStre

8、am for bytes; PrintWriter for character data;,Two Choices for Output: Characters or Bytes,PrintWriter writer = response.getWriter(); writer.println(“some text and HTML”);,Two Choices for Output: Characters or Bytes,ServletOutputStream out = response.getOutputStream(); out.write(aByteArray);,response

9、.sendRedirect(“login.do“),Tomcat,LoginCheck.java,(3)response.sendRedirect(“welcome.do”),返回给tomcatResponse对象,(2)Call this servlet,(1)Request,(4)返回给客户端response对象,状态码301,Tomcat,Welcome.java,(7)处理用户请求后,返回response对象,(6)Call this servlet,(5) 重新发出新的请求,(8)返回response对象,显示登录界面,response.sendRedirect(“login.do“

10、),You cant do a sendRedirect() after writing to the response! If you look up sendRedirect() in the API, youll see that it throws an IllegalStateException if you try to invoke it after “the response has already been committed.”,The differences between GET and POST,GET is meant to be used for getting

11、things. You might use the parameters to figure out what to send back. POST is meant to be used for sending data to be processed. You might use the data of POST body to change something on the server.,The differences between GET and POST,Both GET and POST can send parameters. POST has a body. Limitat

12、ion in GET. Security. Idempotent (幂等性),The difference between GET and POST,An HTTP GET is just for getting things, and its not supposed to change anything on the server. So a GET is, by definition (and according to the HTTP spec) idempotent. It can be executed more than once without any bad side effects. POST is not idempotentthe data submitted in the body of a POST might be destined for a transaction. So you have to be careful with your doPost() functionality.,Step One,Step Two,Step Three,Step Four,

展开阅读全文
相关资源
正为您匹配相似的精品文档
相关搜索

最新文档


当前位置:首页 > 办公文档 > 解决方案

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