When accessing the domain name, directly access the default project and execute the default method - memo "2"

This article is from another blog post of mine [ http://blog.csdn.net/liaohaojian/article/details/78183426 ] Please indicate the reprint

When we enter www.xxxx.com, we can directly access the home page of the xxx website. How is this achieved?

As we all know, when directly accessing a domain name or an IP, if the default project is not configured, only the tomcat interface is displayed. The following explains how to access the default project when directly accessing the domain name or IP.

1. Development environment: springMVC+tomcat

2. The configuration is officially started below, which is mainly divided into the following steps

1) Configure the tomcat default project, configure the tomcat/conf/server.xml file (remember to change the default port number to 80, the setting may fail in linux, the executable command: iptables -t nat -A PREROUTING -p tcp --dport 80 -j REDIRECT --to-port 8080, which roughly means that the port 80 is mapped to 8080 in Linux, so that we can directly enter the domain name without the port number.)

The host part of the code in server.xml is posted below. There are 2 projects in a tomcat, one is default, one needs to be processed, and the reloadable is set to true. When the content is updated, the deployment will be automatically reloaded.

<Host name="localhost"  appBase=""    unpackWARs="true" autoDeploy="true">
<Context path="" docBase="webapps/nengxin" debug="0" reloadable="false"/>
	<Context path="/nengxintest" docBase="webapps/nengxintest" debug="0" reloadable="false"/>
        <!-- SingleSignOn valve, share authentication between web applications
             Documentation at: /docs/config/valve.html -->
        <!--
        <Valve className="org.apache.catalina.authenticator.SingleSignOn" />
        -->

        <!-- Access log processes all example.
             Documentation at: /docs/config/valve.html
             Note: The pattern used is equivalent to using pattern="common" -->
        <Valve className="org.apache.catalina.valves.AccessLogValve" directory="logs"
               prefix="localhost_access_log." suffix=".txt"
               pattern="%h %l %u %t "%r" %s %b" />

</Host>

2) Configure the default execution method of the project.

  1. Configure web.xml, set welcome-file to be empty, the default is to transfer to a view, when it is empty, the default method will be automatically executed when the project is started
    <welcome-file-list>
    	<welcome-file></welcome-file>
    </welcome-file-list>
  2. Define a controller, define a default method
    @Controller
    @RequestMapping(value = "")
    public class LoginController extends BaseController{
    
        @RequestMapping("/")  
        public String showLoginForm(String pwd) { //② Form display  
            return "login";  
        }
        
    }

At this point, the configuration is all complete, publish it, and get it.

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=326718798&siteId=291194637