Struts2 如何在页面之间导航时保​​留表单值? [英] Struts2 how to keep form values when navigating between pages?

查看:27
本文介绍了Struts2 如何在页面之间导航时保​​留表单值?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的项目使用 struts2 + spring3.请帮我解决这个问题.

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

在我的应用中,(a.jsp) 与 --> (aAction.java) 相关.

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

从主菜单,用户可以访问 a.jsp.a.jsp 中有很多字段需要用户输入数据.在页面中间,用户需要转到另一个页面(b.jsp)来添加更多细节.(b.jsp 页面不是弹出窗口) 向b.jsp 添加数据后,用户需要返回a.jsp.如何保留一个.jsp页面数据?

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?

两个页面只使用一个动作 (aAction.java).

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

1) 我可以在 b.jsp 中保留隐藏变量并在 a.jsp 中再次填充数据.但是有很多
a.jsp 中的字段.所以这种方式很乏味.

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.

有没有办法用bean作用域来处理这个问题?或者有什么别的办法吗?

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

推荐答案

有几种方法可以做到这一点

There are several ways to do this

使用 localStorage 而不是会话存储.限制为 5 MB.使用会话存储时需要小心,因为它会影响服务器的性能

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

如果您使用的是 struts,您可以制作自己的类型转换器来传递任何对象.或者,您可以创建一个包含要保留的值的字符串数组,并将其作为参数传递给 struts.xml(见上文).Struts 内置了类型转换器,用于在页面/操作之间持久化字符串数组

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

您也可以将它们保存在 cookie 中,然后在不需要这些值时立即删除 cookie,因为浏览器可以支持的 cookie 数量有限

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

这篇关于Struts2 如何在页面之间导航时保​​留表单值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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