2

I’m using struts2 + spring3 for my project. Please help me to resolve this problem.

In my app, (a.jsp) relate to --> (aAction.java).

From the main menu, user can access a.jsp. There are so many fields in the a.jsp that user need to key in data. In the middle of the page, user needs to go another page (b.jsp) to add some more details. (b.jsp page is not a popup window) After adding data to b.jsp, user needs to come back to a.jsp. How can I retain a.jsp page data?

Only one action use for both pages (aAction.java).

1) I can keep hidden variables in b.jsp and populate data again in a.jsp. But there are so many
fields in a.jsp. So this way is tedious.

Is there any way to handle this problem with bean scope? Or any other way to do?

Roshan
  • 177
  • 2
  • 9
  • 1
    You can put values into the session. Also you can use some of the Struts2 plugins `conversation` or `actionFlow` which will help you to store data between pages. – Aleksandr M Oct 12 '13 at 10:04
  • Thanks for the comments Aleksandr :) – Roshan Oct 12 '13 at 10:44
  • Don't switch pages. With some sensible UI controls (see jQuery UI) and possibly some ajax you can produce a better result with one action. – Quaternion Oct 14 '13 at 05:07
  • 1
    If you do not want to use the session, maybe something like this http://stackoverflow.com/questions/16506132/how-to-pass-a-list-from-one-action-to-another-in-struts-2-without-using-session(iteration of a list) could help you. I would also prefer Aleksandr's solution though. Just keep in mind always what you put in the session. – Stephan May 21 '14 at 14:42

1 Answers1

1

There are several ways to do this

  • use redirectActions in struts.xml. When defining results you can set the type to redirectAction. Then you can redirect to another action and pass params that will be added as parameters to the url http://struts.apache.org/release/2.1.x/docs/redirect-action-result.html

  • use localStorage instead of session storage. Limit is 5 MB. Care needs to be taken when using session storage as it can affect the server's performance

  • if you are using struts, you can make your own type converter for passing any object. Alternatively you could create an string array of the values you want to persist and pass it as a param in struts.xml (see above). Struts has built in type converter for persisting string arrays between pages/actions

  • you could also save them in cookies and then delete the cookies as soon as the values are not needed as there is a limit on the number of cookies browsers can support

  • I usually use session storage as a last resort for the reason mentioned above

steven35
  • 3,747
  • 3
  • 34
  • 48