问题
I am developing an application using Struts 2 and Hibernate.
On a JSP page I have one form in which all CRUD operations I am performing. I want my Form data to be persisted, which is temporarily entered in the form fields.
One approach which I tried is to bind all the data into an Object
and store that object in a session or cache but I know there is some limitation of storing data like this. My form is having the functionality to add n number of rows which means I have to store large amount of data if I use session approach.
So is there any alternative and effective way to do this and yes in a easy manner?
回答1:
Don't use much data in session if you don't need that data anymore. You also need it to implement Serializable
whatever you use a session.
If you are using CRUD application, the data should be available immediately after you save it to the database. Hibernate allows you to get the data from the session.
Don't mess it up with http session. And if the data is not available in the hibernate session hibernate will fetch the data and store it in the cache, then it return the data to you.
来源:https://stackoverflow.com/questions/34481022/whats-the-best-approach-to-persist-form-data-using-struts-2