3 ways to set default access pages under Spring MVC

Source: Internet
Author: User

1. Default page for the default Tomcat container.

/index.html

This is a good way to access static pages (including JSPs) or pages that don't have any parameters.

2.SPIRNG MVC Default Index Controller mode
If the Tomcat container does not have a default page configured, how spring MVC will proactively look for/index controllers, if any, will be called, and no 404 pages will be displayed.
@RequestMapping (value= "/index")
Public Modelandview Index (httpservletrequest request, httpservletresponse response) {
return new Modelandview ("index");
}

3.SPIRNG MVC Configuration root node Access "/" mode
This approach is extreme, is to configure a controller named "/", that is, after entering the URL will be called. This method is not configured for the previous two methods.
@RequestMapping (value= "/") public Modelandview Index (httpservletrequest request, httpservletresponse response) { return new Modelandview ("index"); }

The level of the three methods:1>>3>>2; because Tomcat has a higher container level than spring, and the above 3-clock configuration is the case, use Tomcat preferentially. Because the controller is configured with a "/", it is matched to the relevant controller instead of looking for the/index controller first.

Note that even if Web. XML is not added, Tomcat will automatically default to find the index file under the Webroot directory, and if you want to use the next two methods, make sure that there are no index-related files under Webroot.

If the above method is wrong, please point out that only for learning

3 ways to set default access pages under Spring MVC

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.