如何从< jsp:include/>附带的JSP片段中读取Action属性? [英] How to read Action attributes from JSP fragments included with <jsp:include />?
本文介绍了如何从< jsp:include/>附带的JSP片段中读取Action属性?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
尝试从包含的JSP调用Action的getter时,我得到null:
Trying to call an Action's getter from an included JSP, I get null:
MyAction.java
MyAction.java
private String message = "The message I want to read...";
public String getMessage() {
return message;
}
main.jsp
<%@taglib prefix="s" uri="/struts-tags" %>
<html>
<head></head>
<body>
<div> I'm a DIV in main.jsp </div>
<jsp:include page="fragment.jsp" />
<body>
</html>
fragment.jsp
fragment.jsp
<%@taglib prefix="s" uri="/struts-tags" %>
<div>
I'm a DIV from fragment.jsp
<br/>
Message from Action: <s:property value="message" />
</div>
如何获取JSP片段中的属性值?
How can I get the attribute value in JSP fragment ?
推荐答案
使用 <s:include value="somePage.jsp">
而不是<jsp:include page="somePage.jsp"/>
.
如果您想坚持使用<jsp:include />
,则需要设置
If you instead want to stick with <jsp:include />
, you need to set
<constant name="struts.ognl.allowStaticMethodAccess" value="true"/>
在Struts.xml中,它将像超级按钮一样工作.
in Struts.xml, and it will work like a charm.
Don't ask me why, this is not mentioned anywhere in the documentation, it was a lucky discovery I made some time ago.
这篇关于如何从< jsp:include/>附带的JSP片段中读取Action属性?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文