A brief introduction to Servlet

Servlet introduction:

Servlet is a web server-side programming technology, which implements Java classes with special interfaces. Invoked and started by a servlet enabled web server. A servlet is responsible for one or a group of URL access requests and returns the corresponding response content.

Servlet features:

Run on the application server supporting Java; The server can call the corresponding servlet for request processing according to the request; It is simple, convenient and portable.

Use of servlets:

1. Create a normal java file.

2. The class name of java file implements the method of httpservlet rewriting service.

3. Web under web-inf Add the mapping relationship between request and servlet class in XML.

Servlet running process:

url: http://localhost:8080/firstweb/first

Composition:

Server address: alias of port / virtual project name / Servlet

Uri: virtual project name / servlet alias

Process: the browser sends a request to the server, and the server finds the corresponding project folder under the webapps directory according to the URI information in the request URL address,

Then on the web XML retrieves the corresponding servlet, finds and invokes the servlet, and finally returns the execution result to the browser.

Servlet lifecycle:

Differences between service, doget and dopost methods:

Service method: whether it is a get or post request method, if the service method exists, the service method will be executed first.

Doget method: when there is no service, if it is a get request, call the doget method.

The dopost method calls the dipost method if it is a post request without a service.

Servlet common errors:

Summary:

Although today's enterprises basically won't use servlets, as beginners, servlets must be learned well and are particularly important. We must find out how the client (browser) and the server (Tomcat) interact,

Understand what role servlets play, and the differences and relationships between servlets and Tomcat. Servlet is a specification and a web server programming technology implemented in Java, and Tomcat is a web container that follows the servlet specification, which can also be called

The function of middleware is to parse the client's request and call the server's program according to the standard interface provided by servlet. Of course, our program should also follow the servlet interface specification, get the running result of the server's program, and then return it to the client.

Of course, there are many kinds of middleware, such as JBoss, Weblogic and so on. However, there is only one servlet specification of Java Web. Only these web containers follow the servlet specification of Java, can our Java Web program run correctly on it.

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>