[opencms-dev] State shared between the JSPs

Paul-Inge Flakstad flakstad at npolar.no
Wed Jan 23 12:57:47 CET 2013


Hi again Sankar,

OK, I trust it's not that then. I see you're passing "false" in your 2nd JSP when you're getting the session object. You should probably pass "true" or nothing all.

Here's a real example, in use right now on one of our sites. It works like a charm.

JSP A:
HttpSession sess = request.getSession(true); // Passing "true" here, even though I probably don't have to
sess.setAttribute("share", "true");

JSP B:
HttpSession sess = request.getSession(); // Note I'm not passing no argument here
if (sess.getAttribute("share") != null && sess.getAttribute("share").equals("true")) {
                // Do stuff
}

Please try something like this. Let us know how it goes.

Best regards,
Paul

From: opencms-dev-bounces at opencms.org [mailto:opencms-dev-bounces at opencms.org] On Behalf Of Karri Sankar Rao
Sent: 23. januar 2013 12:47
To: The OpenCms mailing list
Subject: Re: [opencms-dev] State shared between the JSPs

Hi Paul,

In both JSP pages, session="true" in page directives.

Thanks,
Sankar.K

From: opencms-dev-bounces at opencms.org<mailto:opencms-dev-bounces at opencms.org> [mailto:opencms-dev-bounces at opencms.org] On Behalf Of Paul-Inge Flakstad
Sent: Wednesday, January 23, 2013 5:15 PM
To: The OpenCms mailing list
Subject: Re: [opencms-dev] State shared between the JSPs

Hi again Sankar,

The issue is not related to OpenCms, I assure you. Do you have session="true" in your @page directives?

Best regards,
Paul

From: opencms-dev-bounces at opencms.org<mailto:opencms-dev-bounces at opencms.org> [mailto:opencms-dev-bounces at opencms.org] On Behalf Of Karri Sankar Rao
Sent: 23. januar 2013 12:43
To: The OpenCms mailing list
Subject: Re: [opencms-dev] State shared between the JSPs

Hi Paul,

Thanks for your reply. Here is the code.
HttpSession sess = request.getSession(true);

sess.setAttribute("whitePaperRegistrationMailId",regDetails.getEmailId());

String mailId = (String)sess.getAttribute("whitePaperRegistrationMailId");

out.println("Mail id is :"+mailId); //This is working fine in same JSP.



When I am trying to access from another JSP with the below code, I am getting null value.
HttpSession sess = request.getSession(false);

String mailId = (String)sess.getAttribute("whitePaperRegistrationMailId");

out.println("Mail id is :"+mailId); //I am getting null value.

I think the problem is with OpenCMS. Does OpenCMS provide any session management?

Thanks,
Sankar.K
From: opencms-dev-bounces at opencms.org<mailto:opencms-dev-bounces at opencms.org> [mailto:opencms-dev-bounces at opencms.org] On Behalf Of Paul-Inge Flakstad
Sent: Wednesday, January 23, 2013 4:40 PM
To: The OpenCms mailing list
Subject: Re: [opencms-dev] State shared between the JSPs

Hi Sankar,

You do realize you're trying to modify a final object in your illustration code..?
final CmsRequestContext requestContext = cmsObject.getRequestContext();
requestContext.setAttribute("someObj ", someObj);

Anyway -- my preferred recipe goes like this:
// Fetch the session object (don't use the implicitly available variable "session")
HttpSession sess = request.getSession(true); // You may or may not want to pass the boolean here
// Then do like this:
sess.setAttribute(...);
sess.getAttribute(...);

Not forgetting to put session="true" in the @page directive:
<%@page import="..." session="true" %<mailto:%25 at page%20import=>>

You should also be able to use request.setAttribute(...) and request.getAttribute(...) -- just like that, using the implicitly available variable "request". (The stored object will of course live only for as long as the request lives.)

NOTE: If you're using flex cache, be aware. It doesn't always play nice with this. It's supposed to work (if configured correctly) with the session approach, but I've had to disable flex cache for some of my JSPs where I do stuff like this.

HTH :)

Cheers,
Paul

From: opencms-dev-bounces at opencms.org<mailto:opencms-dev-bounces at opencms.org> [mailto:opencms-dev-bounces at opencms.org] On Behalf Of Karri Sankar Rao
Sent: 23. januar 2013 11:16
To: opencms-dev at opencms.org<mailto:opencms-dev at opencms.org>
Subject: [opencms-dev] State shared between the JSPs

Hi,

I am working on OpenCMS application. I am new to OpenCMS.

I have one object which I want to keep it in session so that I can use it in other JSPs.
I tried in 2 ways to get this.

a)      Initially I used JSP implicit variable i.e session.setAttribute("someObj",someObj). But this session object is not available in other JSPs. I am getting null when I try to retrieve using session.getAttribute("someObj");

b)      Then I used another approach.

CmsJspActionElement cms = new CmsJspActionElement(pageContext, request, response);

final CmsObject cmsObject = cms.getCmsObject();

final CmsRequestContext requestContext = cmsObject.getRequestContext();

requestContext.setAttribute("someObj ", someObj);



I am not sure whether it is in request scope or session scope. When I tried to access it in another JSP, getting null value.



CmsJspActionElement cms=new CmsJspActionElement(pageContext, request, response);

final CmsObject cmsObject = cms.getCmsObject();

final CmsRequestContext requestContext = cmsObject.getRequestContext();

Object obj = requestContext.getAttribute("someObj ");

Could you please let me know how to resolve this.

Your help is highly appreciated.

Thanks,
Sankar.K



Disclaimer: "The materials contained in this email and any attachments may contain confidential or legally privileged information. The information contained in this communication is intended solely for the use of the individual or entity to whom it is addressed and others authorized to receive it. If you are not the intended recipient you are hereby notified that any disclosure, copying, distribution or taking any action in reliance on the contents of this information is strictly prohibited and may be unlawful. If you have received this communication in error, please notify us immediately by responding to this email and then delete it from your system. Sonata is neither liable for the proper and complete transmission of the information contained in this communication nor for any delay in its receipt"
Disclaimer: "The materials contained in this email and any attachments may contain confidential or legally privileged information. The information contained in this communication is intended solely for the use of the individual or entity to whom it is addressed and others authorized to receive it. If you are not the intended recipient you are hereby notified that any disclosure, copying, distribution or taking any action in reliance on the contents of this information is strictly prohibited and may be unlawful. If you have received this communication in error, please notify us immediately by responding to this email and then delete it from your system. Sonata is neither liable for the proper and complete transmission of the information contained in this communication nor for any delay in its receipt"
Disclaimer: "The materials contained in this email and any attachments may contain confidential or legally privileged information. The information contained in this communication is intended solely for the use of the individual or entity to whom it is addressed and others authorized to receive it. If you are not the intended recipient you are hereby notified that any disclosure, copying, distribution or taking any action in reliance on the contents of this information is strictly prohibited and may be unlawful. If you have received this communication in error, please notify us immediately by responding to this email and then delete it from your system. Sonata is neither liable for the proper and complete transmission of the information contained in this communication nor for any delay in its receipt"
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://webmail.opencms.org/pipermail/opencms-dev/attachments/20130123/8222ade1/attachment.htm>


More information about the opencms-dev mailing list