Knowledge points of struts2 actions and operations for injecting values to pages using actions

Source: Internet
Author: User


1. In the order of actions, the Action of the package under the specified name will be searched first. If no action is found, the action under the package in the default path will be searched.

2. if no value is set for action, action has some default values. If no class is specified, the default value is ActionSupport. If no method is specified, the default value is execute, if the result attribute is not specified, the success attribute is used by default.

 

3. <package name = "aa" namespace = "/test" extends = "struts-default">

<Action name = "fish">

<Result>/index. jsp </result>

</Action>

</Package>

Use the default value to achieve a simple jump

3. Various forwarding types of results: dispatcher (default); redirect (redirection) Jump to jsp here, But jsp cannot be in the web-inf path; redirectAction,; plainText

 

,

4. What is redirection?

 

Redirection is a special page that provides a mechanism for people to enter the entry or click an internal link pointing to the name, the system can automatically navigate to another relevant page specified in the redirection page, so that the relevant page can be accessed by multiple names. For example, if you set a redirection page pointing to "Australia" named "Australia", anyone can enter the "Australia" name into the Australian entry.

 

During website construction, we often encounter webpage redirection:
1. Website adjustment (for example, modifying the webpage directory structure );
2. The webpage is moved to a new address;
3.modify the extension name of the web page (for example, change ".php" to ".html" or ".shtml ).

5. <global-results> This is a global attempt.

6. <action name = "redfish">

<Result type = "redirect">/index. jsp </result>

</Action>

This is the redirection usage.

 

 

This is the Test. Java file.

Packagecom. fish;

 

Public class Test {

PrivateString username;

 

PublicString getUsername (){

Return username;

}

 

Public void setUsername (String username ){

This. username = username;

}

 

PublicString execute (){

 

Return "success ";

}

 

}

 

 

 

This is a struts2.XML file.

<Package name = "fish" namespace = "/test" extends = "struts-default">

<Action name = "redfish" class = "com. fish. Test" method = "execute">

<Param name = "username"> JOHN </param> // you can set the username value by getting the node.

<Result name = "success">

/MyJsp. jsp

</Result>

</Action>

 

In jsp, we can use the el expression to obtain

The value in $ (username) is John

 

 

Next let's add a paragraph in struts2.xml

<Action name = "aa">

<Result type = "redirectAction"> redfish </result>

</Action>

 

With this action, we can call the view in the above refish, and redirectAction can be another view.

 

We are adding a sentence,

<Action name = "bb">

<Result type = "redirect">/index. jsp </result>

</Action>

Through this, We can redirect him. Redirection changes the page path in the browser and points to the path of the actually existing jsp or action.

 

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.