<J2EE Study Notes> Servlet handouts and j2ee Study Notes
Digress: It was just half a year ago when I got started with java. When I first learned java well, I forgot cpp. Now I have put the hot cpp in my hand and picked it up again, can I remember these two OOP languages clearly?
All of the following are from Teacher Liu Yan of Tongji University (EnterpriseJavaProgramming)
1. What is Servlet?
When I learned J2EE for almost a month, I suddenly began to ask myself, but what is the role of Servlet in MVC Pattern?
Generally, Servlet is a server program under HTTPprotocol. Of course, it means a server program with TCP/IP or UDPprotocol. In the Servlet class, functions that can Override usually have doGet, doPost... which correspond to the method attribute of form labels in the HTML language respectively. The difference between the get method and the post method is that the parameter data queue is added to the URL specified by the action attribute of the submission form, values correspond to each field in the form one by one, which can be seen in the URL. The post method uses the post mechanism of the http protocol to place all fields and content in the form in the httpHeader and transmit them to the URL address specified by the action. The get method is less secure and the post method is more secure. Therefore, we recommend that you use the get method when querying data, the use of the post method is more appropriate when adding, deleting, and modifying data.
Ii. Request & Response Handling
According to the web. the value definition in xml. If we access different addresses. the url-pattern definition in xml delivers different requests and response to different servlets for processing.
To have a deep understanding of the nature of the request object, we call the getContextPath function under the HttpServletRequest interface and other functions as follows:
The first line of getContextPath () is empty because it is not on the server of the Tomcat server. configure the path of the context in the xml file, that is, the virtual directory is path = "", so the first line is an empty string
The string returned by getServletPath () indicates the virtual address provided by the url-pattern attribute in servlet-mapping configured in web. xml.
Row 3 getContextInfo () indicates that when multiple directories are mapped to my url-pattern and a sub-directory is entered, the returned path string "Statement t (SQL)" of the sub-directory is) the path string of the server ".
Iii. About ListenerInterface