aspose file tools*
The moose likes JSP and the fly likes setting session data with javascript Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » JSP
Bookmark "setting session data with javascript" Watch "setting session data with javascript" New topic
Author

setting session data with javascript

RaviNada Kiran
Ranch Hand

Joined: Jan 30, 2009
Posts: 528
I have a JSP page :

In which i would create a session .


I have a button with onclick event

<input type="submit" value="Add" onclick=SetData()/>




If you want something you never had do something which you had never done
Bauke Scholtz
Ranch Hand

Joined: Oct 08, 2006
Posts: 2458
No, it isn't.

Javascript is to Java like Carpet to Car. Only the first few characters match, but further they have completely nothing to do with each other.

Use a Servlet class.
RaviNada Kiran
Ranch Hand

Joined: Jan 30, 2009
Posts: 528
Thanks for your valuable answer.

<input type="submit" value="Add" onclick= <% session.setAttribute("fruits", fruit); %>

I am afraid to post the above code , but posted
Ankit Garg
Sheriff

Joined: Aug 03, 2008
Posts: 9302
    
  17

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...


SCJP 6 | SCWCD 5 | Javaranch SCJP FAQ | SCWCD Links
RaviNada Kiran
Ranch Hand

Joined: Jan 30, 2009
Posts: 528
Can you tell me what is the problem with the second code??
Bauke Scholtz
Ranch Hand

Joined: Oct 08, 2006
Posts: 2458
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.
RaviNada Kiran
Ranch Hand

Joined: Jan 30, 2009
Posts: 528
Thanks Bauke that was a excellent explanation.
RaviNada Kiran
Ranch Hand

Joined: Jan 30, 2009
Posts: 528
Learn the meaning of "server side" and "client side".
Go get yourself a decent JSP/Servlet book. This all is fairly trivial.


Please stop this behaviour from you . It hurts people.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: setting session data with javascript