Question

I have an issue with using jstl inside JSP on Oracle AS 10g. The issue here is that c:out doesn't work with scriptlet variable. In jsp I have something like this:

<%@ taglib uri="http://java.sun.com/jstl/core" prefix="c" %>
<%@ page import="java.io.*"%>
...
<%
String ERROR = request.getParameter("ERROR");
%>
...

(NOTE I had to use http://java.sun.com/jstl/core instead of http://java.sun.com/jsp/jstl/core - this doesn't work for me). And now I try to print it out with c:out tag:

<p style="color: #FF1A00"><c:out value="<%=ERROR%>" /></p>

But it doesn't work. It prints out <%=ERROR%> as red text. I tried to change web.xml tag to include version number and other definitions inside this tag and this doensn't work.

What I had to do is to set this variable to page context and print it from it

<%
pageContext.setAttribute("ERROR", ERROR);
%>
...
<p style="color: #FF1A00"><c:out value="${ERROR}" /></p>

Can somone please explain me what is the problem here and why I couldn't use " />?

Thanks in advance.

Was it helpful?

Solution

You need to understand the difference between scriptlets and jstl

Scriptlets :

scriptlets are transformed into a Java codes and are compiledwhen service method of the JSP is called.

JSTL tags :

Attributes, and by default are scoped at the page context level. As a result, if you need to pass value in a scriptlet to jstl, you can do so by calling the setAttribute() method on the appropriately scoped object (usually pageContext and request)

JSTL works entirely with scoped attributes, either at page, request or session scope

So look here How to avoid Java code in JSP files?

Hope this helps !!

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top