JSP Note--6.servlet Introduction

Source: Internet
Author: User

A servlet, called a server-side applet, is a program that runs on the server side to process response client requests. Ability to handle get, POST, PUT, delete requests from clients. Only get and post are commonly used, and the Doget and Dopost methods need to be overridden in the servlet. Most of the time the servlet responds to all requests in the same way, so only the service method needs to be rewritten.

The Init method in the servlet is used to initialize the servlet resource, and the Destroy method is used to destroy the servlet instance. You usually do not have to write it yourself, if you write it, you need to define the initialization operation in Init, and call the Super.init (config) method on the first line of the method.

Although the JSP can be transferred to a servlet, there is no built-in object in the servlet and needs to be created. For the static HTML part of the JSP, the output stream needs to be output row by line. The service method inside the common servlet class is equivalent to the _jspservice () method of the servlet generated by the JSP.

There are two ways to configure a servlet, one is to use @webservlet, and the other is to take advantage of an XML file. XML, the name and URL of the servlet need to be developed. Examples are as follows:

"Servlet"
" servlet-name" Loginservlet "/servlet-name"
"Servlet-class" com. Loginservlet (package name, class name) "/servlet-class"
"/servlet"
"Servlet-mapping"
" servlet-name" Loginservlet "/servlet-name"
" Url-pattern"/loginservlet "/url-pattern"
"/servlet-mapping"
The contents of " servlet-name" "/servlet-name" in the label "Servlet" and "servlet-mapping" must be consistent

The explanation of servlet and servletmapping

All right, Sina directly turned around, ugly title number ...

This article from "Fingertip Light Fly" blog, declined reprint!

JSP Note--6.servlet Introduction

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.