Java 使用 JSTL 设置请求属性

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/24330155/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-14 11:35:45  来源:igfitidea点击:

Set request attribute using JSTL

javajspjstl

提问by Lluis Martinez

I have the following code:

我有以下代码:

<bean:define id="hasDocuments" name="BudgetSimulationDetailForm" property="hasDocuments" type="java.lang.Boolean"/> 
<%
    request.setAttribute("enablebtnRelatedDocs", "true"); 
    request.setAttribute("hasDocuments", String.valueOf(hasDocuments));
%>

I want to remove the scriptlet, I tried using c:set with different scopes but it didn't work. Is it possible to set a request attribute using JSTL tags?

我想删除 scriptlet,我尝试使用具有不同范围的 c:set 但它没有用。是否可以使用 JSTL 标签设置请求属性?

I tried this and did not work:

我试过这个,但没有用:

<c:set name="enablebtnRelatedDocs" value="true" scope="request"/>

and also

并且

<c:set name="enablebtnRelatedDocs" value="${true}" scope="request"/>

Afterwards there is an include:

之后有一个包括:

<jsp:include page="/gema/jsp/includes/detail/top_Detail.jsp">
    <jsp:param name="title_key" value="${title}" />
    <jsp:param name="title_bundle" value="buc" />           
    <jsp:param name="standard_buttons_include" value="true" />
    <jsp:param name="typeId" value="53555" />
    <jsp:param name="detail" value="budget" />
</jsp:include>

Inside the included JSP the request attribute is not visible, apparently.

在包含的 JSP 中,请求属性显然不可见。

采纳答案by Braj

Sounds Good, You want to use JSP Standard Tag Libraryinstead of Scriplet.

听起来不错,您想使用JSP 标准标记库而不是 Scriplet。

Yes, It's possible using c:set. Read more about Core Tag Library

是的,可以使用c:set. 阅读更多关于核心标签库

<c:set var="enablebtnRelatedDocs" value="${true}" scope="request"/>

<c:out value="${requestScope.enablebtnRelatedDocs }"/>

By default c:setset a attribute in page context. you can set it in any scope.

默认情况下,c:set页面上下文中设置一个属性。您可以在任何范围内设置它。

回答by Andrei Rusu

By default, the JSTL Core library function "set" accepts the following attributes:

默认情况下,JSTL Core 库函数“set”接受以下属性:

JSTL Core set property (credits to tutorialspoint.com) : value, target, property, var, scope

JSTL 核心集属性(归功于tutorialspoint.com):值、目标、属性、变量、范围

You should use "var=" instead of "name=". Hope this helps!

您应该使用“var=”而不是“name=”。希望这可以帮助!

Happy coding! 1: enter image description here

快乐编码! 1在此处输入图片说明