& Lt; J2EE Study Notes & gt; Servlet handouts, j2ee Study Notes

Source: Internet
Author: User

<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

Related Article

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.