내 커뮤니티 업적 표시줄을 확대합니다.

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

Mark Solution

활동이 없어 이 대화는 잠겼습니다. 새 게시물을 작성해 주세요.

해결됨

Difficulty using session object in JSP

Avatar

Level 6

I am trying to pass a value from one jsp page to another.

For simplicity in my example the pages are pg1.jsp and pg2.jsp

In pg1.jsp I do as follows.

HttpSessionContext sc=request.getSession().getSessionContext();

request.setAttribute("name", "clive");

String pg2 ="pg2.jsp";

RequestDispatcher pg2Dispatcher = request.getRequestDispatcher(pg2);

            try {
                pg2Dispatcher .include(request, response);
            } catch (Exception exception) {
                out.println("Error: " + exception);

            }

 

on pg2.jsp 

<%      
   String country = request.getParameter("country"); 
%>
<b> <%=country%>
<%  

This displays "null" on the generated html

 

 

If I try to use session instead.

 

On pg1.jsp 

 

       try {
                session.include(request, response);
            } catch (Exception exception) {
                out.println("Error: " + exception);
       }

 

An error occurred at line: 26 in the jsp file:pg2.jsp
session cannot be resolved
23: 
24: if (desktopDispatcher != null){ */
25:        try {
26:                 session.include(request, response);
27:             } catch (Exception exception) {
28:                 out.println("Error: " + exception);
29:        }

 

I thought that session was automatically available in jsp.

My question is, how can I use Session session, or HTTPSession sesssion inside CQ to pass a variable from one jsp to another?

Regards

Clive Stewart

1 채택된 해결책 개

Avatar

정확한 답변 작성자:
Level 10

Hi Clive Stewart,


1)    Dont use session in aem.
2)    Use getattribute instead of getparameter based on your code.
3)    For session make sure global or cq:DefineObjects is imported.

Thanks,
Sham
Tweet: @adobe_sham

원본 게시물의 솔루션 보기

7 답변 개

Avatar

Level 10

Sham provided an answer to this thread. I will get him to provide the answer again. Looks like in the recent fix- that reply was dropped. 

Avatar

Level 1

Thank you all!!! I have recently used this on my blog www.everydaypowerblog.com and I could not have done it without the thread! Thanks again!!

Avatar

정확한 답변 작성자:
Level 10

Hi Clive Stewart,


1)    Dont use session in aem.
2)    Use getattribute instead of getparameter based on your code.
3)    For session make sure global or cq:DefineObjects is imported.

Thanks,
Sham
Tweet: @adobe_sham

Avatar

Level 1

Thanks for this solutions, finally could sort my issue on my positive quotes website. I want to thank you guys and this community for making things easier.

 

More power to you all!!

Avatar

Level 6

Thank you,I have done as you explained and it worked perfectly.

Avatar

이전 커뮤니티 멤버

Use getattribute instead, getparameter based on your code.

Avatar

이전 커뮤니티 멤버

Use getattribute instead, getparameter based on your code.