Introduction to actionforward in struts1

Source: Internet
Author: User


What does actionforward do? It is used to encapsulate the forwarding and redirection paths. 

In Struts-config. <forward name = "error" Path = "/login. JSP "> </forward> the default value is forwarding. The forwarding feature is that the same request is used, and the redirected URL address changes, while the forwarded URL address remains unchanged. Redirection is redirected from the browser, which means that another request is sent, so the request is not the same, so its URL address will change. To change to redirection, you need to use another property: Redirect = "true". If it is set to true, it becomes redirection. The error page is the page to jump to when a site error occurs, so you should use redirection for the instance. Change the address to the address on the error page.


<Forward name = "error" Path = "/error. jsp" Redirect = "true"> </forward>


Define global forward: use the label <global-forwards> to define global forward: <global-forwards>


<Forward name = "login" Path = "/login. jsp" Redirect = "true"/>


</Global-forwards> global forward can be selected by region. However, when you need to use forward, Struts automatically selects the nearest node. When there is also a definition of the local, it will be converted according to the local. Therefore, public content can be defined globally, such as errors and logon processing. Dynamic actionforward: the static actionforward cannot be changed during the execution period. The callback can be modified during the execution period by using dynamic actionforward.


String page = request. getparameter ("page ");

Actionforward AF = new actionforward ("/page" + Page + ". jsp? Name = wenhq ", true );
// True: Do not use redirection. The default value is false, which indicates redirection.
Return AF;


Static actionforward URLs cannot be added with the number of shards. Dynamic actionforward can be used with the number of shards. 1. Correct Use of forwarding and redirection will make the site URL display more friendly.


2. The configuration of appropriate global actionforward is much more convenient.


3. It is good at using dynamic actionforward and brings convenience to the program.

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.