【问题标题】:how to get java object in child jsp如何在子jsp中获取java对象
【发布时间】:2016-03-22 15:39:17
【问题描述】:

我有两个jsps

  1. init.jsp
  2. second.jsp

init.jsp

PreferenceServices preferenceServices = PreferenceServices.getUserSpecificPreferences(renderRequest);

这里PreferenceServices是一个类,getUserSpecificPreferences(renderRequest)PreferenceServices类的静态方法

second.jsp

<%@ include file="/init.jsp"%>
long documentId = Long.parseLong(preferenceServices.getValue(Constant.DOCUMENT_PREFERENCE, "0"));

这里的preferenceServices是在init.jsp中定义的 getValue(string,string)PreferenceServices 类的方法

现在的问题是, 我无法使用上面的 second.jsp 代码行在 second.jsp 中获得价值

谁能告诉我如何解决这个问题?

谢谢,

拉维·达尔吉

【问题讨论】:

  • 你能解决这个问题吗?

标签: java jsp object parent-child parent


【解决方案1】:

您可以在请求中存储您的值:

<%
request.setAttribute("documentId",documentId);
%>

然后你会在你的 second.jsp 中检索如下:

 <% documentId = request.getAttribute("documentId");%>

使用包含操作:

<jsp:include page="init.jsp" />

何时使用包含操作?

Include 标记不会将被包含页面的源代码包含在当前页面中,而是将包含页面在运行时生成的输出包含在当前页面响应中。 What's the difference between including files with JSP include directive, JSP include action

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2022-11-29
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-09-25
    • 1970-01-01
    • 2020-09-11
    • 2022-07-27
    相关资源
    最近更新 更多