Lluis Martinez Lluis Martinez - 1 year ago 152
Java Question

Set request attribute using JSTL

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?

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" />

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

Answer Source

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

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

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

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

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

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download