Solved

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

Posted on 2003-10-28
6
2,293 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
6 Comments
 
LVL 14

Expert Comment

by:kennethxu
ID: 9647224
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
ID: 9668045
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
ID: 9668255
>>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
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 3

Expert Comment

by:applekanna
ID: 9668274
>>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
ID: 9668779
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
ID: 9673209
my pleasure and glad to know your problem is resolved.
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

We asked our MSP customer base what their favorite tools were and how they help them serve clients. We focused our questions on favorite tools in the following categories: >PSA tools >RMM tools >Alert management tools >Communication tools and Mo…
This post contains step-by-step instructions for setting up alerting in Percona Monitoring and Management (PMM) using Grafana.
Finding and deleting duplicate (picture) files can be a time consuming task. My wife and I, our three kids and their families all share one dilemma: Managing our pictures. Between desktops, laptops, phones, tablets, and cameras; over the last decade…
Suggested Courses

739 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