aspose file tools*
The moose likes HTML, CSS and JavaScript and the fly likes Remove the session attribute while closing the child window Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Engineering » HTML, CSS and JavaScript
Bookmark "Remove the session attribute while closing the child window" Watch "Remove the session attribute while closing the child window" New topic
Author

Remove the session attribute while closing the child window

kapildev ganeshan
Greenhorn

Joined: Feb 15, 2006
Posts: 17
Hi, I have a separate child window from that I have two additional session attributes. While closing the window i want remove those session attribute. The new pages displayed thru a frameset. From that page if I write the method using the
onbeforeunload="handleBrowserX()"

while parsing of that .jsp file (In that time of loading the page) automatically its removing the session attribute and its giving the null pointer exception in the succeeding pages.

So Please give me a suggestion to remove the attribute while closing of that window.


code :
<HTML>
<TITLE>

</TITLE>

<HEAD>
<TITLE></TITLE>
</HEAD>
<script>
function handleBrowserX()
{
alert("Closing the window...*************..");
<% session.removeAttribute("UnApproved")%>
}
<script>


<frameset class="mainBody rows="100%,*" frameborder=0 framespacing=0 onbeforeunload="handleBrowserX()">
<frame src="<%=request.getContextPath()%>/qbe/jsp/SelectLatestVersion.jsp" name=fld_frame>

</frameset>

</HTML>
[ March 21, 2006: Message edited by: kapildev ganeshan ]
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61010
    
  65

Please see this topic as you have the same misunderstanding of the way that JSP s work. You cannot mix Java and Javascript like you are attempting.

That topic has a link to an article that will explain why.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Manesh Kumar
Ranch Hand

Joined: Mar 21, 2006
Posts: 94
Originally posted by kapildev ganeshan:
Hi, I have a separate child window from that I have two additional session attributes. While closing the window i want remove those session attribute. The new pages displayed thru a frameset. From that page if I write the method using the
onbeforeunload="handleBrowserX()"

while parsing of that .jsp file (In that time of loading the page) automatically its removing the session attribute and its giving the null pointer exception in the succeeding pages.

So Please give me a suggestion to remove the attribute while closing of that window.


code :
<HTML>
<TITLE>

</TITLE>

<HEAD>
<TITLE></TITLE>
</HEAD>
<script>
function handleBrowserX()
{
alert("Closing the window...*************..");
<% session.removeAttribute("UnApproved")%>
}
<script>


<frameset class="mainBody rows="100%,*" frameborder=0 framespacing=0 onbeforeunload="handleBrowserX()">
<frame src="<%=request.getContextPath()%>/qbe/jsp/SelectLatestVersion.jsp" name=fld_frame>

</frameset>

</HTML>

[ March 21, 2006: Message edited by: kapildev ganeshan ]


You need to write a seperate jsp or servlet which will remove the session attribute.
Then in onbeforeunload function, you need to call that jsp or servlet using XmlHttpRequest and specifying synchronous operation (false) in third option of open memthod, which will ensure your that your window is not closed before the request is completed.



Hope this helps.


Manesh
kapildev ganeshan
Greenhorn

Joined: Feb 15, 2006
Posts: 17
Originally posted by Dilip Kumar Jain:


Hope this helps.



Thank you Dilip Kumar Jain. i tried like this :
function handleBrowserX()
{
alert("Closing the window...");
//var xmlhttp = new XMLHttpRequest();
var req = new ActiveXObject("Microsoft.XMLHTTP");
req.open("GET", "../qbe/jsp/removeAttribute.jsp", true);
req.send(null);
}

in that specified removeAttribute.jsp file i gave S.O.P for testing as well as I removed those attributes. i didnt get any S.O.P's also session is not removed. Is it above which I written is coreect?
Manesh Kumar
Ranch Hand

Joined: Mar 21, 2006
Posts: 94
Originally posted by kapildev ganeshan:

function handleBrowserX()
{
alert("Closing the window...");
//var xmlhttp = new XMLHttpRequest();
var req = new ActiveXObject("Microsoft.XMLHTTP");
req.open("GET", "../qbe/jsp/removeAttribute.jsp", true);
req.send(null);
}

in that specified removeAttribute.jsp file i gave S.O.P for testing as well as I removed those attributes. i didnt get any S.O.P's also session is not removed. Is it above which I written is coreect?[/QB]



You didnt follow me properly. You need to specify third parameter as false (specifying synchronous operation).
Otherwise browser will proceed to window closing and request will not completed or made at all.

kapildev ganeshan
Greenhorn

Joined: Feb 15, 2006
Posts: 17
Thanks dilip,
function handleBrowserX()
{
req = new ActiveXObject("Microsoft.XMLHTTP");
req.open("GET", "removeAttribute.jsp", false);
req.send(null);
}
If I put like this its going to that specified removeAttribute.jsp and removing the attribute once. Again if I click the button and open the child window from the parent application and if I close the child window using the X(close bar) from window this particular .jsp file is not invoking Any reason for this?
Manesh Kumar
Ranch Hand

Joined: Mar 21, 2006
Posts: 94
Originally posted by kapildev ganeshan:
Thanks dilip,
function handleBrowserX()
{
req = new ActiveXObject("Microsoft.XMLHTTP");
req.open("GET", "removeAttribute.jsp", false);
req.send(null);
}
If I put like this its going to that specified removeAttribute.jsp and removing the attribute once. Again if I click the button and open the child window from the parent application and if I close the child window using the X(close bar) from window this particular .jsp file is not invoking Any reason for this?


I dont find any any reason why it is not firing.
Can you confirm whether it is firing the function handleBrowserX() by giving an alert?
If it is trigerring the function . Then I think IE is caching the page and it is not invoking the call.

You need to set Pragma, Cache-Control and Expires headers so that its contents are not cached.

You can also try by setting the Every Visit to the page option in Temporary Internet Files settting.

You can also check onunload handler instead of onbeforeunload.

[ March 22, 2006: Message edited by: Dilip Kumar Jain ]
[ March 22, 2006: Message edited by: Dilip Kumar Jain ]
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61010
    
  65

Since this has become about Javascript and Ajax, I'm moving this off to the HTML/Javascript forum.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Remove the session attribute while closing the child window