[opencms-dev] State shared between the JSPs

Paul-Inge Flakstad flakstad at npolar.no
Wed Jan 23 13:32:28 CET 2013


Hi again Sankar,

Yes, if you’ve got something in front of Tomcat, that could be causing issues.

We’re using a typical setup with Apache and mod_proxy_ajp in front. In case you’re doing the same, check if you’ve configured the Connector’s “emptySessionPath” attribute in Tomcat’s server.xml.

So, the Connector should look something like this:
<Connector emptySessionPath="true" port="8009" protocol="AJP/1.3" />

Hope this helps.

Cheers,
Paul

From: opencms-dev-bounces at opencms.org [mailto:opencms-dev-bounces at opencms.org] On Behalf Of Ladislav Kulhanek
Sent: 23. januar 2013 13:16
To: The OpenCms mailing list
Subject: Re: [opencms-dev] State shared between the JSPs

Hi Sankar,
we had a problem with session too, it was due to opencms was running on Tomcat on context /opencms and we masked it on Nginx server befor Opencms, so it looked like opencms was running on context /
But session is realized by cookie (which is created by Tomcat) and it looks like this:

JSESSIONID=4871301FB4E4B60F03CAB5DC5AF5CD4D; Path=/opencms
Cookie has a path set, browser then sends this cookie only with requests with path which begins with /opencms. But path was masked by Nginx and request from browser din not have path /opencms. Cookie was not sent and session did not work. Now we are running OpenCms directly on Tomcat on context / and session works properly.
Ladislav Kulhanek

2013/1/23 Paul-Inge Flakstad <flakstad at npolar.no<mailto:flakstad at npolar.no>>
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> [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: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"

_______________________________________________
This mail is sent to you from the opencms-dev mailing list
To change your list options, or to unsubscribe from the list, please visit
http://lists.opencms.org/cgi-bin/mailman/listinfo/opencms-dev




-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://webmail.opencms.org/pipermail/opencms-dev/attachments/20130123/ec18d131/attachment.htm>


More information about the opencms-dev mailing list