RaviNada your second code will also not work. If you want to set a session attribute on the click of a button, then either submit the page to a servlet or make an ajax request to a servlet which will set the session attribute...
Java/JSP runs at the server machine and produces a HTML page.
The HTML page may contain other clientside languages like CSS/JS.
Once Java/JSP is finished producing the HTML page, it sends it to the client side.
Once arrived at the client side, the client starts to interpret the HTML/CSS/JS code.
Do a 'view source' in your webbrowser, you'll see that there is no means of Java/JSP code in there.
Learn the meaning of "server side" and "client side".
Go get yourself a decent JSP/Servlet book. This all is fairly trivial.