i am new to cq5, please help!! I am trying to set hashmap in session attribute. but for some reason i am getting JSP unable to compile. Please help!!
<%@include file="/apps/test/test2/global.jsp"%>
<%@page session="false"
import="org.apache.sling.api.resource.ValueMap,
com.day.cq.wcm.api.WCMMode,
com.day.cq.dam.scene7.api.net.NetUtils,
org.apache.commons.lang.StringUtils,
javax.jcr.Session,
org.apache.jackrabbit.api.security.user.UserManager,
org.apache.jackrabbit.api.security.user.Authorizable" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%
Session session = resourceResolver.adaptTo(Session.class);
Map<String, String> sessionValues = new HashMap<String, String>();
for(int i=0;i<5;i++)
{
sessionValues.put("Id"+i, properties.get("test:Id"+i, ""));
sessionValues.put("Url"+i,properties.get("test:Url"+i,""));
}
// put the hashmap as session
session.setAttribute("map", sessionValues);
%>
The Session you have is a repository session , which is very different from a HTTP Session. Javax.jcr.Session is your gateway to the content repository. It is not used to store session related attributes and does not have any setAttribute method. It is used to read and write to repository ( http://jackrabbit.apache.org/jcr/how-jackrabbit-works.html ). If all your looking for is a http session , you should be getting it from slingRequest.
However if you use http sessions , you cannot cache pages in dispatcher ( https://forums.adobe.com/thread/960708 )