to sum up
In order to better understand the framework, I went to review the basic knowledge of JavaWeb
When I finished the basics of JavaWeb, it was much easier to see Spring, and I could imagine the solution in my mind (of course, I still need to understand how to implement it in detail)
XML
New to JavaWeb, I do n’t know why one part (Servlet, Jsp, Listener, etc.) can be assembled together to form a web page?
Why do various components need to be registered in web.xml?
What is the address of the above bunch in web.xml?
Why <servlet></servlet>
register a servlet container with one label ?
Learn through two chapters of review
Do you really understand XML? -Does XML Basics
really understand XML? -XML parsing method
Roughly understood the idea of implementation:
- XML is a markup language and a data format
- These formats and the above address are Schema constraint technology, which is used to constrain the label content and specify the constraint file address
- The information set in the xml configuration file can be obtained through dom or sax parsing
- After obtaining these configuration information, you can complete the registration through some definition classes inside the server (the specific implementation needs to interpret the Tomcat source code, which cannot be done temporarily)
Servlet
What is Servlet? Why can browser information be processed through Servlet?
Tomcat server = Web server + Servlet / JSP container (Web container)
Servlet is a server-side program written in Java, the main function is to interactively browse and generate data, generate dynamic Web content, Servlet is the specific place to handle business
In Tomcat, the processing of various requests is a variety of Servlets, including the default page processing DefaultServlet, JSP page processing JspServlet, etc.
You can see: Do you really understand Servlet? -Do Tomcat and Servlet
really understand Servlet? -Some details of Servlet
Servlet itself has three levels, Servlet interface, GenericServlet abstract class, HttpServlet class
There are various status objects, domain objects, etc. of the server: What is ServletConfig? What is ServletContext? Need to know
Request和Response
How do browsers and servers communicate?
This involves the HTTP protocol, or network communication protocol mode
Network Communication Protocol (1) Network communication understands the five-layer network model and roughly understands how network communication is done?
Network communication protocol (4) HTTP protocol Understanding the HTTP protocol: how do browsers and servers communicate?
For a browser request, the server will create two kinds of objects: Request and Response.
These two objects also have three levels: Request, Response to ServeltRqeuset, ServeltResponse to HttpServletRequest, HttpServletResponse
Corresponding to the three levels of Servlet: Servlet interface, GenericServlet abstract class, HttpServlet class
HttpServletRequest contains information about the browser request and HTTP protocol. HttpServletResponse is created as an empty object. When the server responds to the browser information, the response information is saved in the Response
Cookie和Session
The specific knowledge of cookies can be seen: Do you really understand cookies-Detailed Cookie
The specific knowledge of Session can be seen: Do you really understand Session-Session Detailed
What are cookies and sessions? Why are cookies and sessions? How to use Cookie and Session?
For historical reasons, the HTTP protocol is stateless.
Stateless: the HTTP protocol does not save temporary data (user name, password, etc.) of the client and server session. The server does not remember the client's information. Each request is independent. of
In order to solve the problems caused by statelessness, the client has a cookie and the server has a session
Cookie is to store the temporary information of the session in the form of a cookie file on the client, you can bring a cookie with each request
That is, cookies are used to store these temporary information, and there is no need to bring a string of parameters after the url when requesting the url
But cookies have certain limitations: it is not safe to store on the client, and it can't carry a lot of information
The Session is stored on the server. The temporary information of these sessions is saved on the server. Only a unique JSESSIONID needs to be created and transmitted to the client. The client can obtain the temporary data of the session by bringing the JSESSIONID when requested. of
But Session can also use cookie technology without using cookie technology.
Listener
JavaWeb has 3 components: Servlet, Listener, Filter
Servlet is processing, Listener is listening
Listener specific knowledge: do you really understand Listener? -Detailed Listener
A picture shows the listener:
The listener can listen to 3 domain objects in the server: Request, Session, Context
The listener involves the observer mode . The observer mode is widely used, including MVC, etc., need to learn
Filter
Filter is a filter
What is a filter ? What is the use? how to use?
Can you really understand Filter? -Detailed Filter
This time roughly understand the operation of the three components:
Through our custom Filter, we can filter out the requests we do n’t need, and we can also filter the response information
The inheritance system of Filter is similar to Servlet: Filter-> GenericFilter-> HttpFilter
Each Filter will be created with the creation of the server, closed and destroyed, and is unique (so multiple filters are required for multiple filters)
There are 4 objects in the Filter that need attention: Request, Response, FilterConfig, FilterChain
FilterConfig is the filter configuration information (ServletConfig can be obtained)
FilterChain is the filter chain, the filter is executed sequentially, and the FilterChain object needs to be connected
JDBC
At this point, how to run the Tomcat service is roughly understood. At runtime, you may need to save data and call data, you must use the database
How does a Java program use a database?
The best way is to connect to the corresponding database driver through JDBC, and connect to the database through the driver
Can you really understand JDBC about the implementation of
JDBC? -Detailed JDBC
JDBC needs to pay attention to 4 objects: DriverManager, Connection, Statement, ResultSet
DriverManager manages the Driver driver registered on it, and the program calls the driver to connect to the database to DriverManager.getConnection(url,name,password);
obtain the connection object through DriverManager (essentially, the database connected to the Driver's connect method)
Connection is an abstraction of the program to connect to the database, the connection is abstracted into an object, and the connection information can be obtained through this object
Statement is a SQL execution object, which is static. Generally, PrepareStatement is used to dynamically execute the object, which not only has many functions, but also is safe to avoid the danger of SQL injection.
There are execute, executeQuery and executeUpdate methods to execute SQL.
ResultSet is a result set, that is, the execution result returned by the database after executing the SQL statement, similar to the iterator, you can iterate to obtain the result
In fact, there are still many details that have not been studied
Json
Both Json and XML are data formats. Why did you choose Json as the data transmission format for the client and server?
Simple understanding of the format and use of Json: Web-Json data exchange format
XML is a heavyweight data format: it
needs a constraint file, it needs a tag definition, and it needs to be parsed.
Json is a lightweight data format:
based on JavaScript's syntax, key-value pairs store data, without parsing, just take the data
JSON is the most popular data exchange format now, and XML is a popular configuration file
Knowledge points not involved
JavaWeb has a lot of knowledge, and also includes front-end knowledge: HTML, CSS, JavaScript, JQuery, etc.
Asynchronous combination of front and back ends: AJAX
dynamic page: JSP
EL expression, etc
Front-end knowledge of HTML is a noun, css adjective, JavaScript is a verb, JQuery JS is an upgrade of
the entry is easy, in-depth complex
AJAX can take a deeper look (but Thymeleaf is too easy to use)
JSP and EL, etc., slowly use less, just understand
Towards the framework
Since ordinary JavaWeb can realize Web development, why should framework?
For my current use, ordinary JavaWeb is too complicated. . .
Servlet, Listener, Filter must be registered in web.xml (Spring can no longer configure XML)
and the use of these components is also very complicated, inheriting the interface, rewriting methods. . .
JDBC connects to the database, each operation must be connected by hand, sql statement (JPA does not need to write sql statement, MyBatis needs to write sql statement but the processing is simple)
front and back end combined with AJAX, and Thymeleaf template can be easily done
I haven't experienced the era of developing Web using JavaWeb, but the framework is really easy to use
In the future, Spring's in-depth learning will begin