-2

This JSP code was working fine in java 8, but not able to run same in java 8.

<c:set var="sAttrib" value="${bean.attrib}" /><% iteratorVal 
((LinkedHashMap)sAttrib).keySet().iterator();   while(iteratorVal.hasNext()) 
{ key = (Integer) iteratorVal.next();  currDev = (Entity)
((LinkedHashMap)sAttrib).get(key);%>

I am getting error as:

sAttrib cannot be resolved.

Thanks in advance.

Santhosh
  • 8,181
  • 4
  • 29
  • 56

1 Answers1

0

When you use <c:set var="sAttrib" value="${bean.attrib}" /> you create what is called a scoped variable, here in page context. You cannot use it directly in scriptlet.

Anyway for you use case, do not use scriptlet but use directly ${bean.attrib} in a foreach :

<c:forEach var="iterator" items="${bean.attrib}">
    ...
</c:forEach>

If you really need to to something in java with a scoped variable you must first get it from its scope :

Map attrib = pageContext.findAttribute("sAttrib");

Or directly :

Map attrib = pageContext.findAttribute("bean").getAttrib();
Serge Ballesta
  • 143,923
  • 11
  • 122
  • 252