java 如何将参数传递给 jsp:include
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/5850954/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
how to Pass param to jsp:include
提问by Sureshkumar Menon
This is my part of jsp file.i am struggling to set param value to SalesClientDetails.jsp.i am not using this style <% %>. How to pass param i tried using jsp:expression but no success.
这是我的 jsp 文件的一部分。我正在努力将参数值设置为 SalesClientDetails.jsp。我没有使用这种样式 <% %>。如何传递参数我尝试使用 jsp:expression 但没有成功。
<jsp:scriptlet>
if (request.getParameter("clientid") != null) {
String clientid = request.getParameter("clientid");
</jsp:scriptlet>
<jsp:include page="SalesClientDetails.jsp">
<jsp:param name="clientid" value= />
</jsp:include>
<jsp:scriptlet>
}
</jsp:scriptlet>
回答by BalusC
Simple, do not use scriptlets, also not in flavor of JSP tags. Use JSTL/EL.
简单,不使用scriptlet,也不具有JSP 标签的风格。使用JSTL/ EL。
<c:if test="${not empty param.clientid}">
<jsp:include page="SalesClientDetails.jsp" />
</c:if>
And in the SalesClientDetails.jsp
just get it by
而在SalesClientDetails.jsp
刚刚得到它
${param.clientid}
回答by Anon
You've created the variable clientId
within a scriptlet, which means that it's a Java variable (versus a value in the page context). So you have to retrieve it with <%= %>
:
您已经在clientId
scriptlet 中创建了变量,这意味着它是一个 Java 变量(相对于页面上下文中的值)。因此,您必须使用以下命令检索它<%= %>
:
<jsp:param name="clientid" value="<%=clientId%>" />