In struts2, & lt; welcome-file & gt; index. action & lt;/welcome-file & gt; directly sets the action, solution of 404, and struts2action404.

Source: Internet
Author: User

In struts2, <welcome-file> index. action </welcome-file> directly sets action, solution of 404, struts2action404

In the past few days, the access to the project page is changed to. action access, and a problem occurs when you modify the home page. Modify <welcome-file> index. action </welcome-file> in the web. xml file to this way. When you access the home page, the system reports a 404 error, which means the file cannot be found. There are two solutions for online query.
Method 1: Create an empty index. action file under WebRoot. This method is simple and practical and is strongly recommended.
Method 2: Because the welcome-file must be an existing file, not an action or servlet Path, you can set a goindex such as <welcome-file>. jsp </welcome-file>, and then goindex. jsp write <jsp: forward page = "index. action "/>. This means that a jsp page is used to forward requests to the action.

Method 3: Use META redirection in index.html.

Actions: <META HTTP-EQUIV = "Refresh" CONTENT = "0; URL = max/HelloWorld. action">

Where,

Content = "1 is the time control, indicating that the page to jump is automatically redirected in 1 second.
Content = "0" indicates that the page will jump to the page you want to jump to immediately.
Url is the path to jump

----------------------------------------------

In struts2, it is also very special:

Cause:

Struts2 uses a filter to process requests. By default, it monitors url address changes.

The following operations are required:

Step 1:
Modify in web. xml
<Filter-mapping>
<Filter-name> struts2 </filter-name>
<Url-pattern>/* </url-pattern>
<Dispatcher> REQUEST </dispatcher>
<Dispatcher> FORWARD </dispatcher>
</Filter-mapping>
Step 2:
Add in web. xml
<Welcome-file-list>
<Welcome-file> index. jsp </welcome-file>
</Welcome-file-list>
Step 3:
Homepage jump statement
The content of index. jsp is as follows:
<Jsp: forward page = "HelloWorld. action"> </jsp: forward>

Or use method 3 !!!

From: http://blog.sina.com.cn/s/blog_4b5bc0110100yrn2.html


How does struts1 configure <welcome file> to access the Action object?

<Action name = "index. do "....
<Wel...> index. do </

How to call action when Struts2 enters the homepage?

There are two ways to achieve this!
1. Create an empty jsp page with the page content
Response. sendRedirect ("/index! Index. action!
<Welcome-file-list>
<Welcome-file> here is your jsp file </welcome-file>
</Welcome-file-list>
2. Create an empty file name under WEB-ROOT as the name of your action (index like this! Index. action as the file name)

<Welcome-file-list>
<Welcome-file> index! Index. action </welcome-file>
</Welcome-file-list>
In this way, you can find your action!
. Do is the same! Understand

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.