Leiste mit Community-Erfolgen erweitern.

Submissions are now open for the 2026 Adobe Experience Maker Awards.

Mark Solution

Diese Konversation wurde aufgrund von Inaktivität geschlossen. Bitte erstellen Sie einen neuen Post.

GELÖST

Cannot get Session Object in JSP

Avatar

Level 6

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

1 Akzeptierte Lösung

Avatar

Korrekte Antwort von
Level 10

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)

Lösung in ursprünglichem Beitrag anzeigen

3 Antworten

Avatar

Korrekte Antwort von
Level 10

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)

Avatar

Level 6

Thank you Scott,

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

Regards

Clive Stewart

Avatar

Employee

Hi Clive,

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

Regards,

Opkar