Forums Register Login

setting session data with javascript

+Pie Number of slices to send: Send
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()/>


+Pie Number of slices to send: Send
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.
+Pie Number of slices to send: Send
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
+Pie Number of slices to send: Send
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...
+Pie Number of slices to send: Send
Can you tell me what is the problem with the second code??
+Pie Number of slices to send: Send
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.
+Pie Number of slices to send: Send
Thanks Bauke that was a excellent explanation.
+Pie Number of slices to send: Send
 

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.
It was the best of times. It was the worst of times. It was a tiny ad.
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com


reply
reply
This thread has been viewed 20895 times.
Similar Threads
Multiple Actions issue in JSF
javascript event ?
How to dynamically "Check" the radio button based on condition
servlet mapping
MultiDimenaional Array sort
More...

All times above are in ranch (not your local) time.
The current ranch time is
Mar 28, 2024 14:46:48.