Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / General / July 2006

Tip: Looking for answers? Try searching our database.

Onchange session removal

Thread view: 
sdavids - 05 Jul 2006 15:36 GMT
Hey all, I am wondering if you can remove a session attribute on an
onchange command, this is what I have:

<SELECT name='TestMenu2' onChange='<%session.removeAttribute("test");%>
clearMenu(2);clearMenu(3);this.form.submit();'>

I have 4 menus which are used to run a SQL query, and the test element
is the data in the final drop down box which is selected. Although if
you change the data in any of the previous drop down boxes I want to
remove the session element of the final drop down box since it is no
longer valid. I use the session.getAttribute("test"); in the page
header to display links since it knows that the final element was
selected. But for some reason this isnt working, so I added:

if((request.getParameter("TestMenu4") == null ||
request.getParameter("TestMenu4").equals(""))&&
session.getAttribute("test") != null){
        session.removeAttribute("test");
    }

to my JSP page which ends up removing the attribute, but doesnt show
the difference in the page header until the page is finally refreshed,
which I dont beleive there is an easy way to do in the if statement. I
tried submitting the form in the if statement after the session
attribute was removed but it lost all of my data from the drop down
box, so I took that out.

Any help would be much appreciated.
Chris Smith - 05 Jul 2006 17:06 GMT
> Hey all, I am wondering if you can remove a session attribute on an
> onchange command, this is what I have:
>
> <SELECT name='TestMenu2' onChange='<%session.removeAttribute("test");%>
> clearMenu(2);clearMenu(3);this.form.submit();'>

No, you can't do that.  JSP scriptlets are executed on the server when
the page is being created, and can't be attached to JavaScript events in
the manner you're trying to do.  The contents of onChange need to be
JavaScript code, which is run on the client.  If you want to remove a
session attribute, you'll have to write your JavaScript to generate a
request to the server, and then have a servlet do it on the server.

> to my JSP page which ends up removing the attribute, but doesnt show
> the difference in the page header until the page is finally refreshed,
> which I dont beleive there is an easy way to do in the if statement.

If you want to change the page content, then that's even more involved.  
Look into accessing the DOM from JavaScript.  None of it is on-topic in
this newsgroup, and I'm sure the people in comp.lang.javascript would be
happy to help.

Signature

Chris Smith - Lead Software Developer / Technical Trainer
MindIQ Corporation



Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.