数据如何在Struts2中传播? [英] How data travels in Struts2?

查看:114
本文介绍了数据如何在Struts2中传播?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图理解Struts2中的数据路径,数据如何放在ValueStack上?如何找出ValueStack中当前存在的对象?我可以从不同的范围应用程序,会话,请求,页面访问哪些其他数据?如何确定我的变量应该具有的范围?

I am trying to understand the path data takes within Struts2, how is data placed on the ValueStack? How can I find out which object is currently present in the ValueStack? What other data can I access from different scopes application, session, request, page? How to decide the scopes my variables should have?

推荐答案

这是很多问题。

值栈只是一种数据结构,是地图和堆栈的组合。命名对象(通过OGNL中的标签访问)在地图中(比如请求范围),搜索属性/方法的对象在堆栈中。

The value stack is just a data structure, sort of a combination of a map and stack. Named objects (accessed via the # tag in OGNL) are in the map (like the request scope, say), objects to search through for properties/methods are on the stack.

< s:debug> 标签是查找价值堆栈中最简单方法的最简单方法。您还可以使用JSP中的裸数组表示法访问堆栈中的任意对象,例如[0]是最顶层的对象, [1]是下一个,等等。这在现实生活中几乎不是一个好主意。

The <s:debug> tag is the easiest way to find out what's in the value stack. You can also access arbitrary objects on the stack using "bare" array notation in JSP, like "[0]" is the top-most object, "[1]" is the next, etc. This is almost never a good idea in real life.

你可以访问任何内容每个范围。

You can access whatever is in each of the scopes.

您自己的对象几乎总是应该通过操作本身放在值堆栈上,或者如果您正在实现 ModelDriven ,通过模型。除此之外,它与任何其他Java EE应用程序相同 - 客户端会话期间所需的对象应该在会话范围内,应用程序中共享的对象应该在应用程序范围内等。

Your own objects should almost always be placed on the value stack via the action itself, or if you're implementing ModelDriven, via the model. Other than that it's the same as any other Java EE application--objects needed for the duration of the client's session should be in session scope, objects shared across the application should be in the application scope, etc.

值栈本身位于请求范围内。

The value stack itself is in the request scope.

这篇关于数据如何在Struts2中传播?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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