[JavaWeb] Tomcat installation and deployment

        In the learning process, there are two common architectures: B/S and C/S. B/S: It is a browser/server model, and the server is accessed through the browser address. C/S: It is a client/server model, which accesses the server through some installation environments . Both are based on the request/response model . First a request is made to the server, and then the server returns a response, and both the response and the request appear in pairs .

       Server: It is a piece of software. As long as the server software is installed on any computer, the resources in the designated directory of the computer can provide external access. Three common server software: Tomcat, weblogic and websphere.

       1. WebLogic.
         Oracle's product is currently the most widely used Web server and supports J2EE specifications. WebLogic is a Java application server used to develop, integrate, deploy and manage large-scale distributed Web applications, network applications and database applications.

        2. WebSphere      

        IBM's WebSphere supports the JavaEE specification. WebSphere is the most important software platform in the on-demand e-commerce era, which can be used for enterprise development, deployment and integration of a new generation of e-commerce applications.

        3. Tomcat    

        Small and medium-sized application systems, free and open source, support JSP and Servlet. Note: Today we are learning and using tomcat server.

Tomcat

      Download and install:

Official website URL: http://tomcat.apache.org/

Just unzip the downloaded compressed package , try not to have Chinese in the installation directory, and tomcat depends on java environment variables .

Use startup.bat in the bin folder of the installation path to test whether the installation is successful:                

                      Successful installation:

The following interface appears to indicate successful installation:

      

     Open the browser and enter in the address bar ( tomcat is in the starting state ): 127.0.0.1 : 8080 :, the following interface appears, then it is successful.

Common problems of Tomcat installation ( startup.bat test page flashed by ):

1), local port conflict: a tomcat may have been started, ()

2), the installation of some special software causes port conflicts

3), JKD environment variable configuration problem. The JAVA_HOME environment variable configures the JDK installation directory, not the bin directory, nor the tomcat installation directory. (Win+R, open the console, enter java -version, if the version information appears, it is not a configuration problem of environment variables.)

4) Compatibility issues of the Windows version (you can change the version directly, I hope you will not encounter it)

      Tomcat catalog introduction:

                         

   idea integrates Tomcat

Tomcat supports publishing J2EE programs, but does not support publishing J2SE and static web

Create a JavaEE project:

                                    

The final module style is as follows (there is a WEB-INF folder in the web directory, which contains a web.xml configuration file. In addition, there is an index.jsp file in the web directory [can be replaced with ".html" file】,):

                                                                              

If there is no web.xml file, you can use the following steps to solve:

Next, start to deploy the tomcat server:

                            

Enter the Deployment interface of the above interface:

Next, create a test file in the src folder:

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

public class Test extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        System.out.println("测试test");
    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        this.doGet(req, resp);
    }
}

Configure the web.xml file under WEB-INF:

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns="http://xmlns.jcp.org/xml/ns/javaee"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd"
         version="3.1">
    <servlet>
        <servlet-name>test</servlet-name>
        <servlet-class>com.james.demotest.Test</servlet-class>
    </servlet>
    <servlet-mapping>
        <servlet-name>test</servlet-name>
        <url-pattern>/myTest</url-pattern>
    </servlet-mapping>
</web-app>

Start the tomcat server for testing:

Enter the test URL in the browser: (localhost:8080/deployment root path/entry path)

Guess you like

Origin blog.csdn.net/weixin_43267344/article/details/108434587