Pages

Friday, January 31, 2014

Passing values between Scriptlet and JSTL..

In this post, I am going show how we should pass the values between scriplet code and JSTL and vice versa...

Some would say "Mixing of both technologies, you should avoid" but in real time applications we have scenarios to pass values in both frameworks.

So here is the implementation to pass the values.

Access scriptlet variable with JSTL

<%
String scripletVariable = "Test";
pageContext.setAttribute("jstlVariable", scripletVariable);
%>

<c:out value="jstlVariable"/>


Access JSTL variable with scriptlet


<c:set var="jstlVariable" value="Test"/>

<%
String scriptletVariable = (String)pageContext.getAttribute("jstlVariable");
out.print(scriptletVariable);
%>

Happy learning :)

No comments:

Post a Comment