Log4X

链路纵横
[搬家文]有关struts2 的标签

因为struts2中的表单属性也定义在action中,所以struts2把整个action放到request中了。

 

经过struts2"加工"的request里面内容分布是下面这样的

         request

                   attrib1

                   attrib2

                   ValueStack

                            ActionContext

                            UserAction

                                     property1

                                     property2

request里面有个ValueStack的东西,里面包含了一个ActionContext和Action本身。

而ActionContext里面又包含了以Map形式展现了的request,session,application等这些scope。

比如

request.getAttribute("a"== ((Map)ActionContext.getContext().get("request")).get("a")
//true

session.getAttribute(
"b"== ((Map)ActionContext.getContext().get("session")).get("b")
//
session.getAttribute("b"== ActionContext.getContext().getSession().get("b")
//also true

 

你可以在action中调用servletActionContext获得HttpServletReqeust对象,直接放入request中,那这个属性就成了上面的attrib1,attrib2。(官方不推荐直接在action中用到servlet API)

你也可以把属性设在action中,那就成了上面的property1,property2了

 

在页面上,这两者都可以用<s:property/>标签取得,但是取得方法是不一样的,property1,2可以直接用

<s:property value="property1"/>

 

这样取到

但是如果你用同样方法取attrib1,如<s:property value="attrib1"/>则什么也不会得到。

如何获得attrib1? 如何用<s:property>获取直接存在request中的属性?

是通过ognl表达式 ,<s:property value="#request.attrib1"/> 这样就行了。

posted on 2008-08-13 20:25  YYX  阅读(337)  评论(0编辑  收藏  举报