jsp 在请求属性中使用 HashMap 包含页面参数
我想将 HTML 页面标题传递到包含的 jsp 页面,但标题被传递到请求属性中的视图,该属性恰好是 hashMap dbTable
这可行,但我不喜欢这样我将 Java 与我的视图混合在一起,
<%@ page import="java.util.HashMap" %>
<% HashMap dbTable = ((HashMap)request.getAttribute("dbTable")); %>
<jsp:include page="inc_header.jsp" flush="true">
<jsp:param name="pageTitle" value="<%= \"Confirm Delete \" + ((HashMap)request.getAttribute(\"dbTable\")).get(\"strTableTitle\") + \" Data \"%>" />
</jsp:include>
我只使用 jsp 1.2,所以这不起作用(标题仅显示 EL 语句)
<jsp:include page="inc_header.jsp" flush="true">
<jsp:param name="pageTitle" value="Confirm Deletion of ${dbTable.strTableTitle} data" />
</jsp:include>
这在页面正文中有效,
<h1>Confirm Deletion of <c:out value="${dbTable.strTableTitle}" /> Data </h1>
但这给出了未终止的字符串错误
<jsp:include page="inc_header.jsp" flush="true">
<jsp:param name="pageTitle" value="Confirm Deletion of <c:out value="${dbTable.strTableTitle}" /> data" />
</jsp:include>
有关于如何做到这一点的想法吗?我的所有视图都使用标头,我想在每个视图模板中构建最终的标题字符串(例如 Confirm Delete
HashMap.DatabaseTitle data
)。
I'd like to pass the HTML page title to an included jsp page but the title is passed to the view in a request attribute that happens to be a hashMap dbTable
This works but I don't like that I have Java mixed in with my view
<%@ page import="java.util.HashMap" %>
<% HashMap dbTable = ((HashMap)request.getAttribute("dbTable")); %>
<jsp:include page="inc_header.jsp" flush="true">
<jsp:param name="pageTitle" value="<%= \"Confirm Delete \" + ((HashMap)request.getAttribute(\"dbTable\")).get(\"strTableTitle\") + \" Data \"%>" />
</jsp:include>
I am only using jsp 1.2 so this doesn't work (title just shows EL statement)
<jsp:include page="inc_header.jsp" flush="true">
<jsp:param name="pageTitle" value="Confirm Deletion of ${dbTable.strTableTitle} data" />
</jsp:include>
This works in the page body
<h1>Confirm Deletion of <c:out value="${dbTable.strTableTitle}" /> Data </h1>
but this gives unterminated string error
<jsp:include page="inc_header.jsp" flush="true">
<jsp:param name="pageTitle" value="Confirm Deletion of <c:out value="${dbTable.strTableTitle}" /> data" />
</jsp:include>
Any thought on how to do this cleaner? The header is used by all my views and I would like to build the final Title String (e.g., Confirm Delete
HashMap.DatabaseTitle data
) in each view template.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您必须至少升级到 JSP 2.0 才能使
中的 EL 正常工作。 JSP 1.2 语法参考 未提及任何 EL支持
,而 JSP 2.0 语法参考 可以。You've to upgrade to at least JSP 2.0 to get EL in
<jsp:param>
to work. JSP 1.2 syntax reference doesn't mention of any EL support in<jsp:param>
, while JSP 2.0 syntax reference does.