Set the default website page and default website page

Source: Internet
Author: User

Set the default website page and default website page
Zookeeper

In the process of website development, we usually have the following requirement: After a visitor enters a domain name, the default page is displayed in the browser. You do not need to enter the name on the homepage, although the name on the pages can be accessed correctly, it does not conform to people's habits. (You can access the home page of hao123 through htt: // www.hao123.com, or through htt: // others ).

Currently, all Web servers can configure the default pages of related websites. IIS can configure the default documents of websites and tomcat can be set through web. xml. However, this configuration usually configures the page under the root directory of the website, instead of the page containing the path. For example, if www.hao123.com is mapped to the hao123 project under tomcat, there is an index. hmtl page under the hao123 project directory, which will be configured in web. xml.

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

What should we do if our home page is contained in a directory? For example, index. jsp is included in the Main folder. Some people may say that adding a path to web. xml is not enough:

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

I have never seen anyone like this. At least not met so far. Therefore, we will not evaluate this method.

Next, we will share with you the solutions I have encountered.

1. All the requests are: web.xmlis configured as the most appropriate, and then written in index.html.

    

Use Page redirection to access the pages we need.

2. In struts, you can configure the root namespace of struts. xml or the default namespace,

    <!—default namespace    <package name="default" extends="struts-default">        <default-action-ref name="index"/>        <action name="index" >            <result type="redirectAction">        <param name="namespace">/Main</param>        <param name="actionName">index</param>    </result>        </action>    </package>     -->    <!—- root namespace-->    <package name="root" namespace="/" extends="struts-default"><default-action-ref name="index"/><action name="index" >    <result type="redirectAction"><param name="namespace">/Main</param><param name="actionName">index</param>    </result></action>    </package>    <package name="Main" namespace="/Main" extends="struts-default"><action name="index" class="com.struts.action.login">    <result>index.jsp</result></action>    </package>

Struts official document description:

The Default namespace matches all namespaces. if an action is not found in other namespaces, the default namespace will be searched.

The default namespace is ""-an empty string. the default namespace is used as a "catch-all" namespace. if an action configuration is not found in a specified namespace, the default namespace is also be searched. the local/global strategy allows an application to have global action deployments outside of the action element "extends" hierarchy.

The Root namespace matches the request in the Root directory of the website.

A root namespace ("/") is also supported. the root is the namespace when a request directly under the context path is already ed. as with other namespaces, it will fall back to the default ("") namespace if a local action is not found.

Therefore, when you directly access the website domain name, the two namespaces will be searched.

 

Comments from people with different opinions are welcome.




Related Article

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.