Scope of the actionform of the Struts1 (life cycle)

Source: Internet
Author: User

Transferred from: http://biancheng.dnbcw.info/java/240347.html

Find a question today: I add a query condition to the list page and then query the data that matches the criteria. The query results are correct. Then I go to the other menu item operation, when I go to the list page again, the system still query according to the query criteria. As long as I don't modify or empty the query criteria, The query condition persists. I used the struts1.
It's strange. I've never met before. First suspect client error:
1: Is it IE cache? The Capture page is indeed being re-requested. The requested URL also does not have the last query condition. That's not the problem with IE caching.
2: Is that a cookie that is not a page that holds the data? The page returned in the grab bag fills in these query conditions directly.
In this way, the problem excludes the possibility of client setting errors. The problem must be on the server, at some point, where the server has saved the actionform!
So I debug server-side code tracing, in the action I wrote to the from has been a query condition, and then to the upper level to find the method of assembling Actionform, in the Struts1 Requestprocessor class, the code is as follows:

private static Actionform Lookupactionform (HttpServletRequest request, string attribute, string scope)
{
Look up any existing form bean instance
if (log.isdebugenabled ()) {
Log.debug (
"Looking for actionform beans instance in scope '"
+ Scope
+ "' under Attribute key '"
+ attribute
+ "'");
}
Actionform instance = null;
HttpSession session = NULL;
if ("Request". Equals (Scope)) {
Instance = (actionform) Request.getattribute (attribute);
} else {
Session = Request.getsession ();
Instance = (actionform) Session.getattribute (attribute);
}
return (instance);
}

From if ("Request". Equals (Mapping.getscope ())) {Request.setattribute (Mapping.getattribute (), instance);} This sentence can be seen, originally when Scorp is request, the form will be saved in the request, otherwise saved in the session. From here to know where the storage, my profile is not configured with the Scope property, the default value is the session, This is where the actionform will be stored in the session.
Here's how to get it: in Requestutils.createactionform (request, mapping, Moduleconfig, servlet), the method invokes another method of its own:

private static Actionform Lookupactionform (HttpServletRequest request, string attribute, string scope)
{
Look up any existing form bean instance
if (log.isdebugenabled ()) {
Log.debug (
"Looking for actionform beans instance in scope '"
+ Scope
+ "' under Attribute key '"
+ attribute
+ "'");
}
Actionform instance = null;
HttpSession session = NULL;
if ("Request". Equals (Scope)) {
Instance = (actionform) Request.getattribute (attribute);
} else {
Session = Request.getsession ();
Instance = (actionform) Session.getattribute (attribute);
}
return (instance);
}

Is this clear? The original is the scope of the ghost. or not deep research on struts, the scope of the role of the property is not understood.
Yes, and it didn't cost much time, and it was a great impression on the scope properties. Oh.
On the internet to check a bit, there are really a lot of people have encountered this problem.

Scope of the actionform of the Struts1 (life cycle)

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.