[英]Jsp include another jsp with Struts2, but no result
我用一个jsp包含另一个jsp,但没有得到任何结果,只有html标签内容。
HelloEmp.jsp:它具有带有 stuts2 标记的迭代器值。
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<%@ taglib prefix = "s" uri = "/struts-tags" %>
<!DOCTYPE html>
<html>
<head>
<title>Hello World</title>
</head>
<body>
<h2>Example of List</h2>
<s:iterator value="helloList">
<s:property /><br/>
</s:iterator>
</body>
</html>
HelloAction.java:它有一个字符串数组
import java.util.ArrayList;
import java.util.List;
public class HelloAction {
private List<String> helloList = new ArrayList<String>();
public String execute() throws Exception {
helloList.add("Jacky");
helloList.add("Natali");
return "success";
}
public List<String> getHelloList() {
return helloList;
}
public void setHelloList(List<String> helloList) {
this.helloList = helloList;
}
}
员工.jsp:它包括HelloEmp.jsp
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<%@ taglib prefix = "s" uri = "/struts-tags"%>
<!DOCTYPE html>
<html>
<head>
<title>Employees</title>
</head>
<body>
<p>An example of the include tag: </p>
<s:include value = "example/HelloEmp.jsp"/>
</body>
</html>
struts.xml:
<package name = "helloworld" extends = "struts-default">
<action name = "hello" class = "example.HelloAction" method = "execute">
<result name = "success">HelloEmp.jsp</result>
</action>
</package>
当我打开employees.jsp时,在HelloEmp.jsp中只能看到标签内容,看不到迭代器值:
但是如果直接打开HelloEmp.jsp,得到的结果是:
请帮我如何解决它? 谢谢你!
而不是使用值使用 page <jsp:include page="Demo.jsp" />
可能会起作用。
最后我改用动作标签,
<s:action name="action_name" executeResult="true"/>
这对我行得通! 谢谢你们。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.