I. Introduction to Servlets
A servlet (server Applet) is the abbreviation for a Java servlet, called a small service or service connector, which is a server-side program written in Java that is designed to interactively browse and modify data to generate dynamic Web content.
Servlet and normal programs, just the source of input information and output results of different goals, so. The function that the common program can complete, the Servlet can also complete.
The servlet is the basic element in Java that handles user requests, and when the user requests the server, the servlet is searched according to the matching rules, and if the servlet is found, its service method is invoked and processed.
Two. Installing Tomcat and Configuration
After installing ISS (Internet Information Service) or Tomcat service, you can become a server.
1. Installing Tomcat 8.0
HTTPS://TOMCAT.APACHE.ORG/DOWNLOAD-80.CGI can go to the official website to download directly
2.tomcat Brief Introduction
Tomcat is a core project of the Apache Software Foundation (Apache Software Foundation) Jakarta Project, developed by Apache, Sun, and other companies and individuals. With Sun's involvement and support, the latest servlet and JSP specifications are always reflected in Tomcat, and Tomcat 5 supports the latest servlet 2.4 and JSP 2.0 specifications. Because of the advanced Tomcat technology, stable performance, and free, so deeply loved by Java enthusiasts and have been recognized by some software developers, become the most popular Web application server.
3. Configuration
Different User Configuration methods may be different below I introduce my configuration method
(1) Inside Eclipse windows→preferences→ Enter Server→runtime environme→ in the search box to add the path to the Tomcat 8.0 in the Add menu
(2) Select a project right-click →properties→java builid path→libraries→add library→server runtime→tomcat
And then it's done.
It is important to note that:
--Default port 8080
--Installation path try not to use Chinese
--different times to start, or error jvm_bind
Three. Start the first servlet program.
It is not surprising that a simple Web page is implemented through a servlet, and it is recommended to use a Chrome browser for the best!
Package Num1;import Java.io.ioexception;import Javax.servlet.servletexception;import Javax.servlet.annotation.webservlet;import Javax.servlet.http.httpservlet;import Javax.servlet.http.httpservletrequest;import javax.servlet.http.HttpServletResponse; @WebServlet ("/servlet1") public class Servlet1 extends HttpServlet {private static final long serialversionuid = 1L; Public Servlet1 () {//TODO auto-generated constructor stub}protected void doget (HttpServletRequest request, Ht Tpservletresponse response) throws Servletexception, IOException {//TODO auto-generated method StubSystem.out.println ( "Hello World"); Response.setcontenttype ("Text/html;charset=utf-8"); Response.setcharacterencoding ("UTF-8"); Response.getwriter (). println ("
Four. XML deployment
Create a new XML page under the Web-inf directory
Java Foundation--servlet (i)