• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Jsp & Javascript

 
Sarah Gaikwad
Ranch Hand
Posts: 35
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am aware of the fact that a jsp scriptlet can be used with a javascrpt function. for example:
function somename(){
somevariable=<%=jspvariable%>
}
works absolutely fine.
My question is can one assign a javascript value to a jsp variable
could someone help me with an example
Sharun
 
Nicholas Cheung
Ranch Hand
Posts: 4982
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Sharun,

My question is can one assign a javascript value to a jsp variable

I dont think JS variables can be assigned to JSP.
JSP variables can assign to JS because, the JS in fact is generated in the server side. And thus, the server side can assign server side variable value to the JS before sending it to the client.
However, the reverse is not true.
At the server side, JS variable contains NO value of the client. (Becos the client does not receive the page yet)
The only way to do this is, you can pass the JS variable as a request, and then send to the JSP as a request parameter, and then assign that value to the JSP variable.
Hope this help.
Nick.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic