Tomcat Configuration Web Default page

Source: Internet
Author: User
Tags html page xmlns tomcat tomcat server
Web Default page

When accessing a web app, you typically need to specify the name of the resource to access, and if you do not specify a resource name, the default page is accessed
For example, when you visit the News page of NetEase Sports, you need to enter
Http://sports.163.com/index.html
Sometimes, I want to enter only
http://sports.163.com/
You can visit the NetEase Sports News page

To achieve this demand
You only need to modify the configuration of the Web. xml file in the Web-inf directory
First, look at the configuration of the Web. xml file under the Tomcat Server installation directory and open the Web. xml file under the <tomcat root directory >\conf directory
The code is as follows

Code description
<welcom-file-list> element, which is used to configure the default page list, which contains multiple <welcome-file> child elements, each <welcome-file> child element, can specify a paging file
When a user accesses a web app, if the page resource is not specified specifically for access, Tomcat follows the <welcome-file-list> element, specifying the order of the default pages, looking for those default pages, and then returning them to the user if found. And stop finding the following default page, if not found, then return to the error prompt page that accesses the resource does not exist configure the Web App default page

In the D drive, create the Chapter02 file
In the Chapter02 file, create a new file welcome.html

Then, configure the virtual directory
Here, using the second method of
In your custom XML file, configure the virtual directory

Configuration complete, restart the Tomcat server
In the browser, access the address
Http://localhost:8080/chapter02/welcome.html
The results are as follows

Configure the default page
Configure the Welcome.html page in the Chapter02 app as the default page
First, in the Chapter02.xml file, create the Web-inf directory
And in this directory, create a Web. xml file that sets Welcome.xml as the default page

Configured as follows

<?xml version= "1.0" encoding= "iso-8859-1"?> <web-app
xmlns= "Http://java.sun.com/xml/ns/javaee"
  Xmlns:xsi= "Http://www.w3.org/2001/XMLSchema-instance"
  xsi:schemalocation= "http://java.sun.com/xml/ns/ Java EE
                      http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd "
  version=" 3.0 ">

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

Restart the Tomcat server to access the address
http://localhost:8080/chapter02/
The results are as follows

Although the name of the resource is not specified in the browser address bar, but you can access the Welcome.xml page
Description, the Welcome.xml page is set to the default page

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.