从一个包含的 JSP 中,我们如何访问另一个包含的 JSP(同一父级)中声明的变量
我有一个父 JSP,其代码看起来像
<jsp:include page='a.jsp' flush='true'/>
<jsp:include page='b.jsp' flush='true'/>
<jsp:include page='c.jsp' flush='true'/>
a.jsp
有一个 Java 对象,我需要在 c.jsp
中访问该对象
有没有办法在不移动任何内容的情况下执行此操作从a.jsp到父jsp的代码?
a.jsp 如下所示:
<%@ page import="com.xxx.yyy.myClass" %>
<%
// Some processing here
%>
<table width="100%" cellspacing="0" class="scrollableTable">
<thead>
<tr>
<%
// Some processing here
w_myObject = myAPI.getmyObject(param1, param2);
// Some processing here
%>
</tr>
<!-- Display contents of w_myObject in subsequent rows of this table, here -->
</thead>
</table>
我想访问 c.jsp 中的 w_myObject
I have a parent JSP with code that looks like
<jsp:include page='a.jsp' flush='true'/>
<jsp:include page='b.jsp' flush='true'/>
<jsp:include page='c.jsp' flush='true'/>
a.jsp
has a Java object which I need to access in c.jsp
Is there a way to do this without moving any code from a.jsp to the parent jsp?
Here is how the a.jsp looks like:
<%@ page import="com.xxx.yyy.myClass" %>
<%
// Some processing here
%>
<table width="100%" cellspacing="0" class="scrollableTable">
<thead>
<tr>
<%
// Some processing here
w_myObject = myAPI.getmyObject(param1, param2);
// Some processing here
%>
</tr>
<!-- Display contents of w_myObject in subsequent rows of this table, here -->
</thead>
</table>
And I want to access w_myObject in c.jsp
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这都与范围有关。如果您的对象在请求范围内,那么它当然可以访问。或者,如果它在会话范围内,它将具有访问权限。但是,如果它在 PageContext 范围内,我相信它将丢失,因为每个 jsp include 创建自己的范围。
所以我想说的是,将对象放入请求范围内,它将在所有 JSP 中可见。
This is all to do with scopes. If your Object is in Request scope then of course it will have access. Or if it is in Session scope it will have access. However, if it is in PageContext scope I believe it will be lost, as each jsp include creates its own scope.
So what I'm trying to say is put the Object in request scope and it will be visible across all JSPs.