質問

I have a struts action flow(struts-1.x framework), which, when executes, the action class ActionFlowActionUnit1.java sets a String variable varName to request using the code

request.setAttribute("varNameFromRequest", varName);

and the flow finally leads to the loading of a jsp Page1.jsp.

Now, Page1.jsp contains a button, which, when clicked, initiates a new struts action flow, which has the action class ActionFlowActionUnit2.java. In this class, I want to use the varName which I had set in request using request.getAttribute().

How can I do it WITHOUT USING SESSION?

Technically, I'm not sure if achieving this using requestis possible, because, triggering a new struts-action will lose all other information in the request that was previously set (if I'm correct).

I couldn't get anything from Google.

役に立ちましたか?

解決

As you say, it is not feasible technically as you want it (every http request from the browser creates a new HttpServletRequest object)

You have 2 options:

  • Using the Session, which you want to avoid as far as I understand
  • Bring back and forth some parameter into every successive request with the value you would like to keep.

The second option would mean to store some parameter inside your Page1.jsp <form> with the variable you need your second action to receive, and then rinse and repeat. This is a pure html form solution.

If you are implementing a complex flow, this looks a fair case to have a look at Spring Webflow. There you can manage flow-level variables, which are stored at a "different" scope than request or session, and looks exactly what you want.

http://projects.spring.io/spring-webflow/

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top