开发者

Update object in Struts action with form values from JSP

I have a struts2 action that builds a form and pre-populates the fields with data from an instance of my object. When I click submit on this form, I get taken to a second action, my formSubmit action. Here I'd like the object to be updated with any new values from the form. Is there an easy way to access this same object in my second action in struts2?

I'd like to, if at all possible, keep my ob开发者_如何学JAVAject in request scope, rather than session.


I'd like to, if at all possible, keep my object in request scope, rather than session.

Well, it is not possible. Think of it: a "request scope" is born when the request starts (the user clicks a button) and dies when the request (the same request, obviously) ends (when the data is sent to the browser). You want to keep an object in a longer-lived scope (probably the session). Or, if the data comes from a DB, load it again in both requests (using perhaps some optimistic locking if are concerned about concurrent changes). These are the typical ways of doing it.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜