直接访问Struts 2动作类属性 [英] Access Struts 2 action class properties directly
问题描述
我想知道是否填充了动作类属性,是否可以直接在结果JSP中访问它们而不将它们分配给动作类中的表单?
I want to know if we populates action class properties, can we access them directly in the result JSP with out assign them to a form in the action class?
推荐答案
Struts2/XWork1及其taglib面向使用的OGNL 所有操作属性的
valueStack
.这些值不是直接的 可用于JSP2.0/JSTL1.1的表达语言.
Struts2/XWork1 and its taglib is oriented towards OGNL, which is using a
valueStack
for all action properties. These values are not direct available for the expression language of JSP2.0/JSTL1.1.
要通过OGNL访问它,只能在Struts标记属性中使用OGNL.例如
To access it via OGNL you can use OGNL only in Struts tag attributes. For example
public String MyAction extends ActionSupport {
private String myAttr;
//getter and setter here
...
<s:set var="myAttrz" value="myAttr" scope="request"/>
${myAttrz} or ${myAttr} will just print out the value.
<%=request.getAttribute("myAttrz")%>
在第一个标签中,以OGNL表达式的形式访问action属性.
在第二行中为JSTL表达式.
在第三行脚本中.
In the first tag the action attribute is accessed as OGNL expression
In the second line as JSTL expression.
In the third line scriptlets.
参考:
- 将Struts和XWork与JSP 2.0和JSTL 1.1一起使用
- 应用程序,会话,在JSP中请求对象
我们可以将JSTL与框架
- Using Struts and XWork with JSP 2.0 and JSTL 1.1
- Application, Session, Request objects in JSP
- Can we use JSTL with the framework
这篇关于直接访问Struts 2动作类属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!