Solved

Getting the session from parent to child window in JSP - (using struts)

Posted on 2003-10-28
6
2,182 Views
Last Modified: 2007-12-19
Hi All,

I am developing a JSP application using struts.

In my application, from my main browser window am opening a child pop up window using javascript.

The problem that am facing is, am not able to get the session object of the parent window in child window. It is creating a new session object in child window.

Code:
for opening the child window in java script-

win = window.open("GfaProjectWeb/commoncsp.do?method=openWorkItemAction&workobjectno="+workObjNum, 'childCSP');


In Action form,
      public ActionForward openWorkItemAction(ActionMapping mapping,ActionForm form,HttpServletRequest request,HttpServletResponse response)
        throws ServletException
      {

HttpSession session = request.getSession();


Here the the session object that is created is having different session ID.


Note: 1. If I open the child page in same browser window(ActionForward), I am able to get the session object. When i open in new window, am facing the problem.

Kindly let me know how to tackle this issue.

Thanks and regards,
Balaji
0
Comment
Question by:balaji_p
  • 3
  • 2
6 Comments
 
LVL 14

Expert Comment

by:kennethxu
Comment Utility
1. make sure you are NOT using IDE intergrated browser, use IE or Netscape.
2. make sure the page you are opening in child window is under same servlet context as the page in parent window.
3. enable cookie on your browser OR encode your url as:
win = window.open("<%=response.encodeURL("GfaProjectWeb/commoncsp.do")%>?method=openWorkItemAction&workobjectno="+workObjNum, 'childCSP');
0
 
LVL 3

Expert Comment

by:applekanna
Comment Utility
Balaji ,
I think this should as it did for me ,
Since you are using JSP you can use the JSESSIONID varaible

In parent window send it as

win = window.open("GfaProjectWeb/commoncsp.do?method=openWorkItemAction&workobjectno="+workObjNum, 'childCSP'&JSESSIONID= <%=session.getId()%> )

at the child window

you can do
HttpSession session = request.getSession(false);

This shouuld work!!!

Do mail me if you need more help.

Cheers!

ps. Kennethxu - correct me if i am wrong
0
 
LVL 14

Accepted Solution

by:
kennethxu earned 50 total points
Comment Utility
>>ps. Kennethxu - correct me if i am wrong
:-)
I'm not sure if that'll work, but at least not all servlet container use JSESSIONID for url rewrite session tracking. so always use response.encodeURL()
0
How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

 
LVL 3

Expert Comment

by:applekanna
Comment Utility
>>so always use response.encodeURL()
Thx for the tip :)


I am using Apache Tomcat and this worked for me ;) from a JSP so worth a shot
0
 

Author Comment

by:balaji_p
Comment Utility
Hi kennethxu,

Thanks a lot... It worked. Actually the problem was using browser integrated with IDE(Point 1). I am using WSAD and it is integrated with IE. But when i tried it using new instance of browser, I was able to pass the session object without any problem.

And since I am able to get the session object, now there is no need for me to pass the session ID as a part of the querystring.....

Once again...thankx for ur immediate reply...which helped me to save a lot of effort....

And applekanna... Thankx for ur suggestion...

Balaji
0
 
LVL 14

Expert Comment

by:kennethxu
Comment Utility
my pleasure and glad to know your problem is resolved.
0

Featured Post

Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

Join & Write a Comment

This article will show you how to create an ISO CD-ROM/DVD-ROM image (*.iso), and MD5 checksum signature, for use with VMware vSphere Hypervisor 6.5 (ESXi 6.5). It's a good idea to compare checksums, because many installations fail because of a corr…
Veeam Backup & Replication has added a new integration – Veeam Backup for Microsoft Office 365.  In this blog, we will discuss how you can benefit from Office 365 email backup with the Veeam’s new product and try to shed some light on the needs and …
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.

744 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now