Struts2 Lifecycle of Action Object

I am new to the Struts2 platform and I really did not have much time to read any Struts2 books. I just learn it on YouTube. Anyway, here is my question.

Presumably my struts.xml looks like this:

<struts> <package name="p1" namespace="/" extends="struts-default"> <action name="login" class="org.tutorial.struts2.action.LoginAction"> <result name="success" type="redirect" >searchTutorialForm</result> <result name="error">/login.jsp</result> </action> <action name="searchTutorialForm"> <result>/searchForm.jsp</result> </action> </package> </struts> 

Let's talk about the p1 package.

If the URL says [http: // localhost: 8080 / Struts2 / login], then the org.tutorial.struts2.action.LoginAction called is called and, after its success, is redirected to the actionTutorial search tag, which calls searchForm. JSP

Thus, the URL the client will see will be [http: // localhost: 8080 / Struts2 / searchTutorialForm] (the goal is not for the client to see [http: // localhost: 8080 / Struts2 / searchForm.jsp])

LoginAction now has some member variables that are displayed in the searchForm.jsp method using a tag. However, using this approach, they are not displayed, as I think the LoginAction object is no longer in the ValueStack (after the redirect, I think?).

Of course, if I do not use the above approach, but instead, as described below:

 <struts> <package name="p1" namespace="/" extends="struts-default"> <action name="login" class="org.tutorial.struts2.action.LoginAction"> <result name="success">/searchForm.jsp</result> <result name="error">/login.jsp</result> </action> </package> </struts> 

then the member variable in the LoginAction object is displayed in the success.jsp file using the tag (but then the user will see the URL [http: // localhost: 8080 / Struts2 / searchForm.jsp])

Basically, my intention is for the user not to see any particular internal file or call as .jsp or .action.

IMPORTANT NOTE: There is no actionTutorialTutorialForm class in the action tag - basically a dummy action.

Question:
1. How to display a member variable in a LoginAction object using the first approach?
2. What is the life cycle of the LoginAction object in the Stack Value?

Thanks.

+4
source share
1 answer
  • Actions are created on request.
  • Redirection triggers a new request.
  • For this, the objects in the previous steps are no longer available.

Questions:

  • You put it in a session or include it as parameters in a redirect.
  • Actions are deleted at the end of the request.
+7
source

All Articles