Cannot get Session Object in JSP | Community
Skip to main content
New Participant
December 17, 2015
Solved

Cannot get Session Object in JSP

  • December 17, 2015
  • 3 replies
  • 1973 views

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.
Best answer by smacdonald2008

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

Employee
December 18, 2015

Hi Clive,

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

Regards,

Opkar

New Participant
December 18, 2015

Thank you Scott,

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

Regards

Clive Stewart

smacdonald2008
smacdonald2008Accepted solution
New Participant
December 17, 2015

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)