How to transmit data between two actions in struts

Source: Internet
Author: User

First, assume that the form in the two actions are of the same type. The first action is called Action1, and the second action is called Action2.
In strutts, if you jump from Action1 to Action2, in Action2, Struts will retrieve data from reqeust (or session or context) and reset it to form. therefore, if you want to transfer data between two actions, you can not set form in Action1, but request, you can directly overwrite the attribute parameter or attribute you want to pass, in the second action, struts will automatically retrieve the data, set it to form, or use another name, manually retrieve the data in Action2, and manually set it to form.
Why? In fact, this is not a struts design mistake, but it is impossible to use form to transmit data, because Action2 does not know that this is passed from other actions, it may be from the client. also, Action2 does not know where the form comes from. therefore, Action2 needs to reset the form value.

[Songsongsong84 ]:
Two methods:

Put a parameter in request. setattribuite.
Use the value of request. Get or in the next action.

Put the parameter in the session attribute.

If you don't know how to perform this operation, let's just say it. I'll help you write it, but remember, I need to ask other people's questions for points.

[Qulin52 ]:
This method is not worth the value. I have tried it for a long time.
Request. setattribute ("policype", policypeid );
Get to null

[Qulin52 ]:
Request. getsession (). setattribute ("policype", policypeid );
Not in the session.

[Qulin52 ]:
I have seen a solution on the Internet, but it is troublesome!

[Songsongsong84 ]:
That's not possible. The action is servlet, so neither servlet can use session to pass the value.

[Qulin52 ]:
The problem is that you cannot wait ~ I can't get any numeric values directly.

[Songsongsong84 ]:
How to write it?

[Qulin52 ]:
Request. getsession (). setattribute ("policype", policypeid );
Request. getsession (). setattribute ("nettype", nettypeid );

Policypeid = (string) request. getattribute ("policype ");
Nettypeid = (string) request. getattribute ("nettype ");

[Qulin52 ]:
I'm sure the policypeid is not blank when it is passed in!

[Songsongsong84 ]:
Policypeid = (string) request. getattribute ("policype ");
Nettypeid = (string) request. getattribute ("nettype ");

Changed:

Remember httpsession session = request. getsession ();
Policypeid = (string) Session. getattribute ("policype ");
Nettypeid = (string) Session. getattribute ("nettype ");

[Songsongsong84 ]:
You didn't write it right at all. You can use the session to get your variables in the properties of the Session. Do not use the request.

[Qulin52 ]:
Try me

[Mianwo602 ]:
<Action Path = "/tawwpyear/checklistpass" parameter = "checklistpass"
Type = "com. boco. EOMs. Workplan. Controller. tawwpyearaction"
Scope = "request" Validate = "false">
<Forward name = "success" Path = "/tawwpyear/checklist. Do"
Redirect = "true"/>
</Action>
You have written redirect = "true" here. This is a direct jump. That is to say, the set value in the first action cannot be obtained in the second action. You can use the session. I don't think so.
Solution: Remove redirect = "true ".

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.