Today to do a training in-house, seemingly wrong object, should not talk to the new people so the original rational things.
Anyway, or put it up, do not know if anyone can clarify the logic ^ _ ^
Question: Why use Tomcat
Tomcat:servlet container
Servlet + Container
What is the basis of the Web?
Network programming: Links, data
Links: Socket/serversocket
Data: Inputstream/outputstream Stream
What is the data? Bits! Transmission in the network
However, BITS is not what we want, we want information information!
What is information? Bits + context! Csapp
What is the context of Web programming?
TCP, UDP ...
However, this is only the bottom of the surface!
Protocols such as TCP and UDP are themselves for data transfer
How to interpret? or context!?
http!
So,Java Web Network programming is: Create links, and then according to the HTTP protocol format to resolve those transmitted by the TCP protocol data! Be sure to understand this.
Therefore, you must be familiar with the format of the HTTP protocol!
Is it
No!
This is just the body part of the HTTP protocol ! Be sure to understand this.
The problem comes: every time you have to be responsible for the link, tired not tired? It is also necessary to consider optimizations such as concurrent workloads, which require sufficient professional knowledge.
What are the characteristics of Java programming? Let the professional people responsible for professional things!
So the Java EE Community put forward the concept of servlet + servlet container.
The servlet is responsible for the business logic, while the servlet container is responsible for the application, release, and routing of the request! A clear division of labor can be more focused on their own part.
In addition, there is the concept of filter, listener, which occurs because of the characteristics of the container!
Container server, app server, Web server APACHE CGI
Servletcontextloaderlistener, Requestattributelistener
Since the container is responsible for functions such as linking, routing, and so on, it can be handled differently at different stages of the life cycle, before or after the project is loaded, before or after the servlet loads, after the link is created, before or after the route. This is useful to implement some of the requirements more succinctly-similar to the construction method, static code block, dynamic code block, etc. that are executed when the object is created. In addition, spring beans have a similar life cycle.
Yes, and JSP, why do you need this?
Because it is cumbersome to return pages in a servlet, use strings to stitch up HTML statements.
The JSP is much simpler, but in fact, it is turned into a servlet's class file, except that the contents of the output have been converted into strings by the container.
That is, this is a technique that simplifies the servlet's return of HTML content.
The question comes again: since there is a servlet, servlet Container, why are struts, Spring MVC and other frameworks?
This is because the servlet has only the most basic functions, the deeper requirements need to be implemented by users themselves, including synchronous asynchronous processing, codec, parameter/entity class object conversion, internationalization and other functions.
What is the core class of struts? Web. XML Preparexxxxfilter Action Multiple cases
What are the core classes of Spring MVC? Web. XML dispatcherservlet url-mapping/** single case
Why should you have your own core class?
Why are the two different? -Can the core class of struts be replaced by similar SPRINGMVC?
Java Web Knowledge Grooming