Servlet Merge

1. Steps to develop a web project:

 1: Create a web project
 2: Import third-party jar (connection pool, mysql) packages, and script files corresponding to the database, etc.
 3: Add configuration files, db.properties
 4: Write tool classes, DBUtil, etc.
 5: Write the corresponding data according to Dao's ideas The code
        includes:
        entity class, interface, implementation class
 6: Write the code of the business layer---- (M layer: model, including the persistence layer and the business layer)
 7: Write the Servlet component. (C layer: controller, control layer)    
 8: Configure the web.xml file

Second, the test part:

   Step 1: Start the server tomcat
   Step 2: Deploy the project to the server (code update, need to be redeployed)
   Step 3: Enter the request path on the browser.
   

3. The container handles the problem of requesting resource paths:

 1: What is the request resource path? ?
  http://localhost:8088/appName/xx.html; /appName/xx.html is the request resource path.  2: How the container handles the request resource path    (1) The browser sends a request to the container through IP and Port to establish a connection.    (2) Find the corresponding application in the server according to appName (deployment name), and then         match the value of <url-pattern> in web.xml according to xx.html.              After the match is successful, execute the corresponding web component.  3: Exact match.         When the container processes the requested resource path, it will first         find the value of <url-pattern> strictly and accurately. For example, if the requested resource         path is: appName/addEmp.html, it will first         check whether any of the values ​​of <url-pattern> is addEmp. html;         If there is, the corresponding web component will be executed         (even if there is an addEmp.html page at this time, the page will not be displayed)   4: Wildcard matching.     *: Can match n any characters,            if the value of <url-pattern> is /*, it means that any requested resource path          will execute this web component.     reg:
           

















      http://ip:port/appName/abc
      http://ip:port/appName/abc.html
      http://ip:port/appName/abc/abc.html
  5: Suffix match.
          If <url-pattern> The value is *. suffix, at this time, "/" must not be added before *.
         When the requested resource path is in the format of this suffix, the corresponding web component
      
    reg:
       <url-pattern>*.do<url-pattern> will be executed to
    request the resource path:
    http://ip:port/appName/abc.do
    http://ip:port/appName/abc/abc.do
  6: No matching servlet processing
       If the requested resource path does not have any match in web.xml, it will look
      for this file. If there is, the file will be responded to the browser, if not,
      a 404 error will be reported.
      
      Summary: Three matching priorities
            Exact matching > Wildcard matching > Suffix matching
 

    Fourth, the merger of Servlet components

       1: Why merge?
              Because the Servlet component acts as a controller, it is
              used to distribute different resources by analyzing the resource path. Therefore, a Servlet component
              can distribute different resources. 
       2: How to merge?
             request.getRequestURI(): This method returns the
             request resource path, and we can use the branch structure to control
             the distribution of resources.
             reg:
             String path =request.getRequestURI();   
             if("/appName/listEmp.do").equals(path){
              //
             }else if(("/appName/deleteEmp.do").equals(path)) {
               //
             }         
            The jar package that needs to import the mysql connection pool;
      

     




 
 
   

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325511671&siteId=291194637