Javaweb09-html Notes (ii)

Source: Internet
Author: User
Tags html notes

1.1 Case One: Use a servlet to complete a user logon case. 1.1.1 Requirements:
On the homepage of the website, login link, click the login link, you can jump to the login page. Enter the user name and password in the login page click the log in case. Complete the login function.

1.1.2 Analysis: 1.1.2.1 Technical Analysis:
"Overview of the HTTP protocol"

? 协议:* 什么是协议:规定双方需要遵守的规则.? HTTP协议:* 什么是HTTP协议:用来规定浏览器与服务器之前需要遵守的规则. ![](http://i2.51cto.com/images/blog/201805/21/4e240f07b0bd6b1c9545ff695376ff85.png?x-oss-process=image/watermark,size_16,text_QDUxQ1RP5Y2a5a6i,color_FFFFFF,t_100,g_se,x_10,y_10,shadow_90,type_ZmFuZ3poZW5naGVpdGk=)? HTTP协议的作用:规范浏览器和服务器之间的数据传递.? HTTP协议的特点:* 基于请求和响应的模型.    * 必须先有请求后有响应.    * 请求和响应必须成对出现.* 默认的端口号是80.? HTTP协议的版本:* 1.0   :每次响应后即刻关闭了连接.* 1.1   :现在使用.不是每次响应后挂断,等待长时间以后没有请求会挂断.

"Demo of HTTP Protocol"

Packet Capture Analysis: GET mode: * Request section: get/day09/demo1-http/demo2.html?name=aaa&age=23 http/1.1accept:text/html, application/xhtml +xml, */*x-httpwatch-rid:59176-10011referer:http://localhost:8080/day09/demo1-http/demo1.htmlaccept-language: zh-cnuser-agent:mozilla/5.0 (Windows NT 6.3; WOW64; trident/7.0; rv:11.0) like Geckoaccept-encoding:gzip, deflatehost:localhost:8080dnt:1connection:keep-alive clutch Analysis: Post mode: Post/ Day09/demo1-http/demo2.html http/1.1accept:text/html, Application/xhtml+xml, */*x-httpwatch-rid: 59176-10031referer:http://localhost:8080/day09/demo1-http/demo1.htmlaccept-language:zh-cnuser-agent:mozilla/ 5.0 (Windows NT 6.3; WOW64; trident/7.0; rv:11.0) like Geckocontent-type:application/x-www-form-urlencodedaccept-encoding:gzip, Deflatehost:localhost : 8080content-length:15dnt:1connection:keep-alivecache-control:no-cachename=bbb&age=38* Response section: HTTP/1.1 200 okserver:apache-coyote/1.1accept-ranges:bytesetag:w/"145-1461807615933" Last-modified:thu, APR 01:40:15 GMTContent-type:text/htmlcontent-length:145date:thu, APR 01:43:52 gmt<! DOCTYPE html>

"An explanation of the HTTP protocol"

?            Request Part * Request Line * Submission Method: * Submission method There are many, commonly used get and post: * Get and post differences: * Get the submitted parameters will be displayed to the address bar, and post does not display.            * Get is often limited by size, while post has no size limit.    * Get has no request body, while Post has request body.    * Submission Path: * Protocol version: * The request header * is displayed in the form of a key-value pair. Typically a key corresponds to a value, and there is an individual key that corresponds to multiple value. * User-agent: Represents the type of browser.    ---file download: Download the Chinese file: IE uses Urlencodor to encode, while Firefox uses BASE64 encoding. * Referer: Represents the source of the Web page.    ---anti-theft chain. * If-modified-since: Typically used with header last-modified in the response to find the local cache. * The request body * is the submit parameter of the Post submission method.        Response section * Response Line: * Protocol version * Status code: * 200: Success * 302: REDIRECT * 304: Find local cache * 404: resource does not exist    * 500: Server Internal Error * Status Code description * Response Header: Key value pair, usually a key corresponding to a value, there is a key corresponding to more than one value.    * Last-modified: Use with if-modified-since in the request to find the local cache.    * Content-dispostion: The use of a header information for file download.    * Location: Redirect The path of the jump. * Refresh: Timed refresh/timed jump. * Response Body: Displays the contents of the browser's page. "Overview of the servlet"? What is servlet:* is a small Java program running on a Web server that receives and responds to requests sent from the client, typically using the HTTP protocol. * Servlet is a dynamic web development technology provided by Sun company. Role of the servlet: * Used to process requests sent from the client browser and can respond to requests? Use servlet:* to write a class to implement a servlet interface. * Configure this class to be written to the server. Getting Started with Servlets: * Writing classes: public class ServletDemo1 implements servlet{@Override/** * Methods for users to process requests and responses. */public Void Service ( ServletRequest req, servletresponse Res) throws Servletexception, IOException {res.getwriter (). println ("Hello Servlet ...");} ...} Configuration
``` test1 com.itheima.a_servlet. ServletDemo1 test1 /servletdemo1 * Access: Http://localhost:8080/day09/ServletDemo1 "use ServletRequest to receive parameters"! [] (http://i2.51cto.com/images/blog/201805/21/be54d20c345f503507a7b200efb6297d.png?x-oss-process=image/ watermark,size_16,text_qduxq1rp5y2a5a6i,color_ffffff,t_100,g_se,x_10,y_10,shadow_90,type_zmfuz3pozw5nagvpdgk=) * String GetParameter (string name); ---is used to receive data with a name that corresponds to a value. * string[] getparametervalues (String name),---used to receive data with a name that corresponds to multiple values. * Map getparametermap (); ---is used to receive all the data in the form, the map key is the parameter name submitted by the form, and the value of map is the values of the commit parameter. * Enumeration Getparameternames ()---used to get the names of all the arguments submitted in the form. " servlet Access Process "servlet implementation Relationship" Servlet: interface | Genericservlet: a common servlet | Httpservlet:httpservlet* writes a class that inherits HttpServlet, overriding the Doget and Dopost methods. * Configure ' 1.1.3 Code implementation 1.1.3.1 Step One: Create DATABASE and table: "' Creation Database Day09;use day09;create table user (ID int primary KEY auto_increment,username varchar), password varchar (20), Nickname varchar); INSERT into user values (null, ' AAA ', ' 111 ', ' Xiao Feng '); INSERT into user values (null, ' BBB ', ' 111 ', ' small Tongtong '); "' 1.1.3.2 Step Two: Create packages and classes: 1.1.3.3 Step three: Introducing the jar package ' * MySQL'sDatabase Driver Package * C3P0 Connection Pool JAR Package * dbutils package ' ' 1.1.3.4 introduced login page 1.1.3.5 write servlet-->service-->dao1.1.4 summary: 1.1.4.1 The life cycle of a servlet: (* * * *) "? Life cycle: Is the process of creating an object from creation to destruction. Servlet life cycle: The process from creation to destruction of Servlets. * When to create: the first time a user accesses a servlet to create an instance of a servlet * when destroyed: When the project is removed from the server, or when the server is shut down. When a user accesses the servlet for the first time, the server creates an instance of the servlet, Then the Init method in the servlet executes. Any one request server creates a new thread to access the service in the servlet. The method of doxxx is called within the service method, depending on how the request is made. (GET request call Doget,post request call Dopost). When the servlet is removed from the server, or the server is shut down, the instance of the servlet is destroyed, and the Destroy method executes. "1.1.4.2 servlet related configuration : "Create servlet at startup" The servlet is created by default at the time of the first visit. Now let the servlet be created when the server is started. Configure the servlet: in Web. xml Label Configuration: * 2 ---Pass in a positive integer, the smaller the integer, the higher the priority is created. Configuration of Url-pattern Url-pattern configured in three ways: 1. Full path match:/start for example:/servletdemo4,/aaa/servletdemo5,/ aaa/bbb/servletdemo62. Directory match: Start with/to end with *. For example:/*,/aaa/*,/aaa/bbb/*3. Extension matches: Cannot start with/start with *. For example: *.do, *.action***** the wrong wording:/*.do "" Like the following configuration: " ServletDemo4 com.itheima.a_servlet. ServletDemo4 ServletDemo4 /servletdemo4 ServletDemo5 com.itheima.a_servlet. ServletDemo5 ServletDemo5 / * ServletDemo6 com.itheima.a_servlet. ServletDemo6 ServletDemo6 *.do If Access address: Http://localhost:8080/day09/ServletDemo4: First http://localhost:8080/day09/aaa.do: Second * * * * * Full path match > directory match > Extension matches the path written in the "1.1.4.3 Development:"? Relative paths: All are required to find a positional relative relationship. Cannot start with. *./current path. /Top level directory * Using relative path access: * http://localhost:8080/day09/demo4-url/demo1.html * http://localhost:8080/day09/ServletDemo6? Absolute path: Does not need to find a positional relative relationship. To/from. * The absolute path is divided into the client path and the server side path: * Client path must add engineering name. /DAY09/SERVLETDEMO6 * Server-side path does not require an engineering name. /servletdemo6 ""

Javaweb09-html Notes (ii)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.