How does the javaweb project configure the start page as a dynamic address

In the javaweb project, we can set the start page by configuring <welcome-file-list> in web.xml, as follows:

<welcome-file-list>
	<welcome-file>index.html</welcome-file>
	<welcome-file>index.jsp</welcome-file>
</welcome-file-list>

 Through this configuration, when accessing the url: http://localhost:8080/project name  , it will directly enter the index.html or index.jsp page.

 

However, this method can only configure the start page as a static page, if it is configured as a dynamic url, such as:

<welcome-file-list>
	<welcome-file>user/login.shtml</welcome-file>
</welcome-file-list>

When accessing, a 404 error will be reported.

 

This is due to the logical flow of tomcat:

    For the configuration in welcome-file, tomcat will determine whether the root directory file exists, and if not, it will return 404 directly.

 

Solution: Create user/login.shtml in the webapp directory to deceive tomcat. Tomcat determines that the root directory file exists, continues the process, and then hands it over to spring for processing, and successfully configures the start page as a dynamic url.

 

The spring configuration in web.xml is as follows:

	<servlet>
		<servlet-name>SpringMVC</servlet-name>
		<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
		<init-param>
			<param-name>contextConfigLocation</param-name>
			<param-value>classpath:spring-mvc.xml</param-value>
		</init-param>
		<load-on-startup>1</load-on-startup>
		<async-supported>true</async-supported>
	</servlet>
	<servlet-mapping>
		<servlet-name>SpringMVC</servlet-name>
		<url-pattern>*.shtml</url-pattern>
	</servlet-mapping>

 

Guess you like

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