Tomcat and HTTP protocol, servlet consolidation

Source: Internet
Author: User

Make a flag, after all write with Markdown. The first time does not use, the writing is too ugly, but the last article wrote that called a beauty.

Back to the theme, blogging is to review, these days simple to the Web part of the study. Tidy up some, first put these have been sorted out. 1. Tomcat

Still the old Xmind:

As a server, Tomcat is primarily learning to use, and there is a need to include projects that interact with each other.

1. The Javaweb project is written by the Java background writing logic, HTML and so on page display. And such a project requires interaction, that is, Java and Tomcat interaction need to use a rule--servlet.
2. On the other hand, after Tomcat executes the project, the external client is able to access the page through the browser, when the client displays and obtains the data on the server and needs to use another rule--http. 2. Servlet

The first contact servlet, a bit difficult to understand, do not understand the specific functions of this thing, javaweb part of the knowledge is composed of several pieces together, this interaction between these methods, protocols, etc. too important. HTTP in the ordinary life of some contact to have some understanding, JDBC in code writing can clearly express the idea of their interaction, the servlet is indeed the first contact, see the program is not very understand why he is so.

Xmind First:
Overview
After developing the Web project, we all need to run the project to the server, which is Tomcat, but this web project, the simplest HTML-formatted page tomcat can directly identify the run, and then the browser will be able to display the corresponding page, but in the project, We all need to process the data and use Java to do a primary data processing work on the front and back end, which has a high demand for Java and other parts of the interaction, and Java language Tomcat is not directly recognized, so need such a servlet such a protocol.

So what exactly does the servlet do?

start with the development step. define a class inheritance HttpServlet

/** inherits the HttpServlet need to implement its two methods, which are used for the interaction of HTTP submissions/Public
class Servletdemo extends httpservlet{
    @Override
    protected void doget (HttpServletRequest request, httpservletresponse response) {
        System.out.println ("get");
    }
    @Override
    protected void DoPost (HttpServletRequest request, httpservletresponse response) {
        System.out.println ("post");
    }
Configuring Web.xml Files
<servlet>
    <servlet-name>demo</servlet-name>
    <servlet-class> com.servlettest.servletdemo</servlet-class>
</servlet>
<servlet-mapping>
    < servlet-name>demo</servlet-name>
    <url-pattern>/test</url-pattern>
</ Servlet-mapping>
Then publish the project, run Tomcat, and use the browser to access: Http:/localhost:8080/web/test

I don't understand. So start with the wheel and analyze his process one more step:
A. Browser Access address: http:/localhost:8080/web/test
B. Using the HTTP GET method to send a request to the server
C.tomcat will first identify web.xml files
1. Visit to Url-pattern
2. Match Servlet-name, find servlet program
D. Go to the servlet program, run the Get method, and then respond.

Ps:
Servlet alone this is actually a bit blurry, but after adding the JSP should be able to understand

Jsp

Java servlet page:
This is a Java-capable HTML file, but its internal source code is a Java program, using a print stream to write an HTML file, this is a page layout file and data processing of the Java integration of the new format file.
When the browser accesses the path that the file matches in the Web.xml file, it automatically finds the file path, displays it, and its associated servlet's Java files. Interact in such a step-by-step manner. 3. HTTP protocol


Xmind:

The above mind map to do more specific, more than to repeat.

In fact, HTTP transmission process has a series of encoding and decoding process, if the transmission between the Chinese, in the absence of special processing will appear garbled, this point will be opened a chapter to narrate.


Not to be continued ....

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.