Off-topic: Touch Java is half a year ago, the first time to learn Java but the CPP to forget, and now put the heat of the CPP to put down again to pick up the Java, whether these two OOP language I can clearly separate remember it
All of the following courseware from Tongji University Liu Yan Teacher (enterprisejavaprogramming)
I. What is a servlet?
The problem is that when I learned one months of the Java EE suddenly began to ask myself, yes, our code is finished, the server is running, but what is the role of the servlet in MVC pattern?
Generally speaking servlet refers to the server program under Httpprotocol, of course, it means that there is TCP/IP or UDPPROTOCOL server program. The functions we can override in a servlet class are usually doget,dopost. These doxx correspond to the method property of the form label in the HTML language, respectively. It's also easy to say that the Get method is the difference between the Get method and the Post method, which means that the parameter data queue is added to the URL of the Action property of the submission form, and the value corresponds to each field one by one in the form, which is visible in the URL. The Post method uses the post mechanism of the HTTP protocol to place the fields and their contents within the Httpheader into the URL address specified by the action in the form. Get method security is relatively low, post method security is relatively high, so it is recommended to do the data query when using the Get method, and when the data additions and deletions to change the use of post method will be more appropriate.
Two. Request&response Handling
According to the definition of the value in Web. XML, the words that we access to different addresses will be delivered to different servlets for different request and response according to the definition of Url-pattern in Web. Xml.
In order to have a deep understanding of the nature of the request object, we call the Getcontextpath of the HttpServletRequest interface, and so on:
The first line Getcontextpath () is empty because we do not configure the context path in the Tomcat server's Server.xml file, which means that the virtual directory is path= "", so the first line is an empty string
The second line of Getservletpath () returns the string of things we have configured in Web. XML with the virtual address provided by the Url-pattern property in Servlet-mapping
The third line of Getcontextinfo () is when multiple directories are mapped in my url-pattern, and the path string "except (SQL) server" of the subdirectory is returned when one of the subdirectories is entered.
Three. About Listenerinterface
<J2EE Learning notes > handouts for Servlets