尝试从包含的 JSP 调用 Action 的 getter,结果为 null:
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
<%@taglib prefix="s" uri="/struts-tags" %>
<div>
I'm a DIV from fragment.jsp
<br/>
Message from Action: <s:property value="message" />
</div>
如何获取JSP片段中的属性值?
最佳答案
使用 <s:include value="somePage.jsp">
而不是<jsp:include page="somePage.jsp"/>
.
如果您想坚持使用 <jsp:include />
,您需要设置
<constant name="struts.ognl.allowStaticMethodAccess" value="true"/>
在 Struts.xml 中,它会像魅力一样工作。
别问我为什么,this is not mentioned anywhere in the documentation ,这是我不久前的一个幸运发现。
关于jsp - 如何从 <jsp :include/>? 包含的 JSP 片段中读取 Action 属性,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19425754/