使用Struts 2保留表单数据的最佳方法是什么? [英] What's the best approach to persist form data using Struts 2?

查看:72
本文介绍了使用Struts 2保留表单数据的最佳方法是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Struts 2和Hibernate开发一个应用程序.

I am developing an application using Struts 2 and Hibernate.

在JSP页面上,我使用一种形式执行所有CRUD操作.我希望我的表单数据能够持久保存,并暂时在表单字段中输入.

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.

我尝试的一种方法是将所有数据绑定到Object并将该对象存储在会话或缓存中,但是我知道存储这样的数据存在一些限制.我的表单具有添加n行数的功能,这意味着如果使用会话方法,则必须存储大量数据.

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?

推荐答案

如果您不再需要会话中的数据,请不要在会话中使用太多数据.无论您使用会话如何,也都需要它来实现Serializable.

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.

如果使用CRUD应用程序,则将数据保存到数据库后应立即可用. Hibernate允许您从会话中获取数据.

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.

不要搞乱http会话.而且,如果数据在休眠会话中不可用,则休眠将获取数据并将其存储在缓存中,然后它将数据返回给您.

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.

这篇关于使用Struts 2保留表单数据的最佳方法是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆