Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

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

Posted on 2003-10-28
6
Medium Priority
?
2,444 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
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 200 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
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
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

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

Simulator games are perfect for generating sample realistic data streams, especially for learning data analysis. It is even useful for demoing offerings such as Azure stream analytics, PowerBI etc.
Do online retailers and e-commerce sites even need to bother with the season? Is it lucrative to update and prepare your site for Black Friday and Cyber Monday shoppers? We'll find out now.
Want to learn how to record your desktop screen without having to use an outside camera. Click on this video and learn how to use the cool google extension called "Screencastify"! Step 1: Open a new google tab Step 2: Go to the left hand upper corn…
In response to a need for security and privacy, and to continue fostering an environment members can turn to for support, solutions, and education, Experts Exchange has created anonymous question capabilities. This new feature is available to our Pr…
Suggested Courses

783 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