Skip to main content
Level 6
Dec 17, 2015 11:34 AM UTC
Solved

Cannot get Session Object in JSP

In my global.jsp file on line 44 I have

I want to try use session such as

session.setAttribute(userIDKey, userID);

on a jsp page.

in global.jsp I  have

--%><%@page session="false" import="javax.jcr.*,

If I change it to

--%><%@page session="true" import="javax.jcr.*,

then every page I try display give

/libs/foundation/global.jsp(44,4) Page directive: illegal to have multiple occurrences of session with different values (old: false, new: true)

 

else

If I leave global.jsp with

--%><%@page session="false" import="javax.jcr.*,

 

And I try enable session on my jsp page

<%@page contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" %>
<%@include file="/libs/foundation/global.jsp"%>
<%@page session="true"%>

I get

org.apache.sling.api.scripting.ScriptEvaluationException: org.apache.sling.scripting.jsp.jasper.JasperException: /apps/components/comps/compponentexample/compponentexample.jsp(3,0) Page directive: illegal to have multiple occurrences of session with different values (old: false, new: true)

 

Is there a way to be able to use session object in aem 6.1

This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.
smacdonald2008
smacdonald2008Accepted solution
Level 10
Dec 17, 2015 2:42 PM UTC

Modify content under libs is not best practice  - that includes /libs/foundation/global.jsp. 

Getting a session in JSP is similiar to using Java on backend. Here is a community article that show you the syntax: 

http://teknopoint.us/adobe-cq5-code-snippets-cheat-shs/

(I personally prefer using OSGi to create sessions and perform CRUD operations on JCR data that require a session)

3 replies

smacdonald2008
smacdonald2008Accepted solution
Level 10
Dec 17, 2015 2:42 PM UTC

Modify content under libs is not best practice  - that includes /libs/foundation/global.jsp. 

Getting a session in JSP is similiar to using Java on backend. Here is a community article that show you the syntax: 

http://teknopoint.us/adobe-cq5-code-snippets-cheat-shs/

(I personally prefer using OSGi to create sessions and perform CRUD operations on JCR data that require a session)

Translate
Level 6
Dec 18, 2015 5:43 AM UTC

Thank you Scott,

I will use your recommendation use an OSGI bundle to set and retrieve session values on the JCR.

Regards

Clive Stewart

Translate
Adobe Employee
Dec 18, 2015 8:57 PM UTC

Hi Clive,

what is your use case for maintaining a session? What data are you wanting to use across requests?

Regards,

Opkar

Translate