Update : the code is now in github along with instructions to reproduce the bug (in README.md
> Instructions to reproduce jstl - el - read element from map). See my other question for the format of my jsp files. I still haven't figured this out
This works :
<%
HttpSession ses = (HttpSession) request.getSession(false);
if(ses != null) {
HashMap<String, String> m = (HashMap<String, String>) ses.getAttribute("messages");
if(m != null) { %>
<%=m.get(request.getParameter("r")) %>
<%}
}
%>
This doesn't :
<c:set var="key" value="${param.r}"/>
<c:out value="${key}" /> <!-- does print what I expect -->
<%-- ${sessionScope.messages} prints nothing --%>
sess scope : ${sessionScope} <%-- prints sess scope : {} --%>
<c:out value="${sessionScope.messages[key]}" /> <!-- nothing !? -->
why ?
jstl-1.2.1 - tried also with 1.2
The relevant jsp (error_begin.jsp - complemented by an error_end.jsp containing just a closing }
) :
<%@ page language="java" pageEncoding="UTF-8"%><!-- noway to include this ONCE -->
<%@page import="java.util.HashMap"%>
<% if(request.getAttribute("ErrorString") != null){ %>
Υπήρξε λάθος : ${requestScope.ErrorString}
<%} else { %>
<c:if test="${param.r != null}">
<div class="success" align="center">
<%
HttpSession ses = (HttpSession) request.getSession(false);
if(ses != null){
HashMap<String, String> m = (HashMap<String, String>) ses.getAttribute("messages");
if(m != null){ %>
<%=m.get(request.getParameter("r")) %>
<%}
}
%><c:set var="key" value="${param.r}"></c:set>
<%-- <c:out value="${key}" /> --%>
<%-- ${sessionScope.messages[key]} --%>
<%-- ${sessionScope.messages} prints nothing --%>
sess scope : ${sessionScope} <%-- prints {} --%>
<%-- <c:out value="${sessionScope.messages[key]}" /> --%>
<%-- <c:out value=" ${messages[param.r]}" /> --%>
</div>
</c:if>
<c:forEach items="${messages}" var="entry">
Key = ${entry.key}, value = ${entry.value}<br>
</c:forEach>
Relevant part of Web.xml :
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"
version="3.0">
javax.servlet.jsp.jstl-1.2.1.jar
javax.servlet.jsp.jstl-api-1.2.1.jar
joda-time-2.1-javadoc.jar
joda-time-2.1.jar
logback-classic-1.0.7.jar
logback-core-1.0.7.jar
mail.jar
mysql-connector-java-5.1.22-bin.jar
slf4j-api-1.7.2-javadoc.jar
slf4j-api-1.7.2-sources.jar
slf4j-api-1.7.2.jar