The Javaweb Foundation enables servlet classes and servers to start together by configuring Web. Xml

Source: Internet
Author: User
Tags apache tomcat

Li Wu:
Learn to think more, honouring teachers save Thanksgiving. Leaf See Root 321, rivers with one.
Meekness Conscience Lord, willing to do without regrets to the most bitter. Reading exercise strong body and mind, Prudential advised and the line and cherish.



Javaee:7
javase:1.8
jstl:1.2.2
Server:tomcat 8.5
Explorer:firefox
Os:windows7 x64
Ide:myeclipse



Project directory Structure

Xml

<?xml version= "1.0" encoding= "UTF-8"? ><web-app xmlns:xsi= "Http://www.w3.org/2001/XMLSchema-instance" xmlns= "Http://xmlns.jcp.org/xml/ns/javaee" xsi:schemalocation= "Http://xmlns.jcp.org/xml/ns/javaee/http Xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd "id=" webapp_id "version=" 3.1 "><servlet><servlet-name> specialservletone</servlet-name><servlet-class>jizuiku.web.servlet.specialservletone</ servlet-class><load-on-startup>0</load-on-startup><!--Start the service in a non-negative number from large to small once--></servlet ><servlet-mapping><servlet-name>specialservletone</servlet-name><url-pattern>/ Specialservletone</url-pattern></servlet-mapping><servlet><servlet-name> specialservlettwo</servlet-name><servlet-class>jizuiku.web.servlet.specialservlettwo</ servlet-class><load-on-startup>1</load-on-startup></servlet><servlet-mapping>< Servlet-name>specialservlettwo</servlet-name><url-pattern>/SpecialServletTwo</url-pattern></servlet-mapping><servlet>< servlet-name>commonservlet</servlet-name><servlet-class>jizuiku.web.servlet.commonservlet</ Servlet-class></servlet><servlet-mapping><servlet-name>commonservlet</servlet-name> <url-pattern>/CommonServlet</url-pattern></servlet-mapping></web-app>

Parsing an XML file shows that there are three servlet classes. Where Specialservlettwo, Specialservletone start with the server startup, and Commonservlet is normal, have access to start.

  
Commonservlet

Package Jizuiku.web.servlet;import Java.io.ioexception;import Javax.servlet.servletexception;import Javax.servlet.http.httpservlet;import Javax.servlet.http.httpservletrequest;import javax.servlet.http.httpservletresponse;/** * * * *  @author to the hardest * @version V17.10.20 */public class Commonservlet Extends HttpServlet {/** *  */private static final long serialversionuid = 1L; @Overridepublic void Init () throws Servle texception {//TODO auto-generated method StubSystem.out.println ("Commonservlet started");} @Overrideprotected void Doget (HttpServletRequest req, HttpServletResponse resp) throws Servletexception, IOException {/ /TODO auto-generated method stub} @Overrideprotected void DoPost (HttpServletRequest req, HttpServletResponse resp) Throws Servletexception, IOException {//TODO auto-generated method stub}}

Specialservletone

Package Jizuiku.web.servlet;import Java.io.ioexception;import Javax.servlet.servletexception;import Javax.servlet.http.httpservlet;import Javax.servlet.http.httpservletrequest;import javax.servlet.http.httpservletresponse;/** * * * *  @author to the hardest * @version V17.10.20 */public class Specialservletone extends HttpServlet {/** *  */private static final long serialversionuid = 1L; @Overridepublic void in It () throws Servletexception {//TODO auto-generated method StubSystem.out.println ("Specialservletone started");} @Overrideprotected void Doget (HttpServletRequest req, HttpServletResponse resp) throws Servletexception, IOException {/ /TODO auto-generated method stub} @Overrideprotected void DoPost (HttpServletRequest req, HttpServletResponse resp) Throws Servletexception, IOException {//TODO auto-generated method stub}}

Specialservlettwo

Package Jizuiku.web.servlet;import Java.io.ioexception;import Javax.servlet.servletexception;import Javax.servlet.http.httpservlet;import Javax.servlet.http.httpservletrequest;import javax.servlet.http.httpservletresponse;/** * * * *  @author to the hardest * @version V17.10.20 */public class Specialservlettwo extends HttpServlet {/** *  */private static final long serialversionuid = 1L; @Overridepublic void in It () throws Servletexception {//TODO auto-generated method StubSystem.out.println ("Specialservlettwo started");} @Overrideprotected void Doget (HttpServletRequest req, HttpServletResponse resp) throws Servletexception, IOException {/ /TODO auto-generated method stub} @Overrideprotected void DoPost (HttpServletRequest req, HttpServletResponse resp) Throws Servletexception, IOException {//TODO auto-generated method stub}}

Part of the console output when the server starts

Info: Starting Servlet engine:apache tomcat/8.5.23 October 20, 2017 9:10:41 pm Org.apache.catalina.startup.HostConfig deploydire Ctory Info: Deploying Web application directory [E:\develop\apache-tomcat-8.5.23\webapps\Day09] October 20, 2017 9:10:41 pm  Org.apache.jasper.servlet.TldScanner Scanjars Info: At least one JAR is scanned for TLDs yet contained no TLDs. Enable Debug Logging for the logger for a complete list of JARs that were scanned and no TLDs were found in them. Skipping unneeded JARs during scanning can improve startup time and JSP compilation time. Specialservletone started Specialservlettwo started October 20, 2017 9:10:41 pm Org.apache.catalina.startup.HostConfig Deploydirectory Info: Deployment of Web application directory [E:\DEVELOP\APACHE-TOMCAT-8.5.23\WEBAPPS\DAY09] has Finished in [729] Ms October 20, 2017 9:10:41 pm org.apache.catalina.startup.HostConfig deploydirectory Info: Deploying Web Applica tion directory [E:\develop\apache-tomcat-8.5.23\webapps\docs] October 20, 2017 9:10:41 pm Org.apache.catalina.startup.HosTconfig deploydirectory Info: Deployment of Web application directory [E:\develop\apache-tomcat-8.5.23\webapps\docs] has Finished in [+] Ms October 20, 2017 9:10:41 pm org.apache.catalina.startup.HostConfig deploydirectory Info: Deploying Web Applicat Ion directory [E:\develop\apache-tomcat-8.5.23\webapps\examples] October 20, 2017 9:10:42 pm Org.apache.catalina.core.ApplicationContext Log Info: contextlistener:contextinitialized () October 20, 2017 9:10:42 pm Org.apache.catalina.core.ApplicationContext Log Info: sessionlistener:contextinitialized () October 20, 2017 9:10:42 pm Org.apache.catalina.startup.HostConfig deploydirectory Info: Deployment of Web application directory [E:\develop\ Apache-tomcat-8.5.23\webapps\examples] have finished in [429] Ms October 20, 2017 9:10:42 pm Org.apache.catalina.startup.HostConfig deploydirectory Info: Deploying Web application directory [E:\develop\ Apache-tomcat-8.5.23\webapps\host-manager] October 20, 2017 9:10:42 pm Org.apache.catalina.startup.HostConfig Deploydirectory Info: Deployment of Web ApplicatIon directory [E:\develop\apache-tomcat-8.5.23\webapps\host-manager] have finished in [$] Ms October 20, 2017 9:10:42 pm Org.apa Che.catalina.startup.HostConfig deploydirectory Info: Deploying Web application directory [E:\develop\ Apache-tomcat-8.5.23\webapps\manager] October 20, 2017 9:10:42 pm Org.apache.catalina.startup.HostConfig deploydirectory Info : Deployment of Web application directory [E:\develop\apache-tomcat-8.5.23\webapps\manager] have finished in [] Ms October 20, 2017 9:10:42 pm Org.apache.catalina.startup.HostConfig deploydirectory Info: Deploying Web application directory [e:\ Develop\apache-tomcat-8.5.23\webapps\root] October 20, 2017 9:10:42 pm Org.apache.catalina.startup.HostConfig Deploydirectory Info: Deployment of Web application directory [E:\develop\apache-tomcat-8.5.23\webapps\ROOT] has finished  In [+] Ms October 20, 2017 9:10:42 pm Org.apache.coyote.AbstractProtocol start Info: Starting Protocolhandler ["http-nio-8081"] bodyguards 20, 2017 9:10:42 pm Org.apache.coyote.AbstractProtocol start info: Starting PROTOCOLHAndler ["ajp-nio-8009"] October 20, 2017 9:10:42 pm Org.apache.catalina.startup.Catalina start info: Server Startup in 1383 MS 

When the browser accesses the Web page for the Commonservlet

Learning resources: Itcast and Itheima Video library. If you have public resources, can share to me, with your resources to learn also can.
Blog post is to watch the video, into thinking written. It's good that the teacher speaks well. Blog bad, is to give the most bitter not serious.

The Javaweb Foundation enables servlet classes and servers to start together by configuring Web. Xml

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.