2017-9-11-a-WebServer

Source: Internet
Author: User

1
*/index.html
*/reg?username=fancq&password=123456&nickname=
* In a GET request, the URI may have both of the above conditions.
* The HTTP protocol specifies that a URI in a GET request can pass parameters, whereas a rule is requested after the resource is
* “?” Split, followed by all parameters to be passed, each parameter by:
* Name=value format is saved, and each parameter is split with "&".
* The processing requirements here:
* Will "? "Before the content is saved to the property URI.
* After each parameter is stored in the attribute parameters
* Where key is the parameter name and value is the values of the argument.
* 1: Instantiate HashMap for initializing properties parameters

2 Learning the context of the project is the key, the overall grasp of the project, in fact, the creation of methods is only second, the teacher to the overall control of the project is the most valuable.
Why is there a direct definition here, do not need to consider the different cases of processing,
The teacher tests the method of thinking, new a class, passing in parameters, calling methods.
In the case of post, does it need to be taken into account if I add a change in the parameters? If so, how does the teacher design the function to achieve this effect.
In combination with object-oriented thinking, the whole process is actually the process of initializing all kinds of objects and finally returning the target object.

Skill ①, shun before the process of thinking, and see where the need to make changes
As in file.exists there is now a judgment to add a if all equals Reg.

3 What is the overall business process for a server?
Create a new server to fetch requests, read processing requests, return request resources
Wrap the latter two processes into the Clietnhandler (new Class), and once a new request creates a new thread, it needs to be managed with a thread pool because of the number of threads.
The main process in ClientHandler is the Run method, the Run method (that is, the process of fetching, reading, processing the request),
The Run method contains-
① reads the request, converts the request item to an object, and facilitates subsequent retrieval to determine the returned data.
The object includes the request header and the message header lookup table, writes the method that handles the object--directly into the input stream, translates the request directly into the request object--greatly reducing the amount of code
Message header
There are two types of requests in the ① message header, which need to be handled separately
② the message header lookup table must be instantiated before use, or it will not be used
The criteria for jumping out of a loop is to return a string length of 0 instead of full equal to null or "". (StringBuilder maintains an empty string internally by default)
② returns a request to instantiate the property of the response as an object.
The Request object contains:
Status line, response header (header), Response Body (web Resource)
The corresponding attribute is passed into the object in its native data type and then converted directly internally to the output stream
Can be directly used out output, but it is more recommended to load on the buffered stream output, greatly accelerate the speed

4 Use "/reg". Equals (URI) or uri.equals ("/reg")?
"/reg". Equals (URI), Uri.equals ("/reg")

6 How to understand the object-oriented programming idea in Webserver project? How should you program with OOP ideas?
Objects are docked to objects through methods, and methods are wrapped inside objects.
Originally passed property into the method to pass the object with a property, greatly reducing the amount of code (when more than one attribute is required, and the property belongs to an object)
Understanding the Webserver project process with object-oriented thinking:
Life is also an object an object is processed, and its properties and methods may be called when the object is used.
A large object is the server, the server object, which can receive processing requests for this object, returning a response object.
For process programming, the variables that appear in the process are judged by whether they belong to an object, if it is encapsulated.
The use of object-oriented, but also greatly clarify the idea of programming, an object to deal with an object, the relationship between objects and objects clearly clear.

7 so the processing registration function is handled separately with one class, and the incoming request and response.

8 User submission information is not directly accessible, or directly return to the lookup table (you can directly remove,add operation) so how to deal with it?
Defines a function that gets a parameter, rather than a method that returns an object directly
public string GetParameter (string name) {
return Parameters.get (name);
}

9 What is the principle of registration?
Catch keyword Reg, call module,
Server corresponding principle-capture keywords, return to the specified address.

10 re-reel learn in the morning

11 How do I return a page response to the client?
Response Success Page to client
File File = new file ("WebApp" + file.separator + "reg_ok.html");
Response.setstatus (HTTPCONTEXT.STATUS_CODE_OK);
Response.setcontenttype ("text/html");
Response.setcontentlength ((int) file.length ());
response.setentity (file);
Response.Flush ();

12 What do we need to know?
When refactoring, what can be placed in the configuration file.
Tap the Web server again.

What are the advantages of the 13 database?
Save large amounts of data in a secure and persistent format.

2017-9-11-a-WebServer

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.