-1

Eg : I have var a=10; now i want to use value of 'a' in jsp tag like

 <% int b= "how to store javascript variable here"

  %>
user2431829
  • 125
  • 1
  • 3
  • 6

2 Answers2

1

You can set the javascript variable value in a hidden field before submit/process it in server side, so it will be sent as part of Request parameters

document.getElementById('myHidden').value=myVariable;

To access the javascript variable in server side code

Request.getParameter("hiddenName")
Murali Murugesan
  • 22,423
  • 17
  • 73
  • 120
  • i want the opposite one like, i want to store javascript variable in jsp variable Eg: int jspvariable= "java script variable" how to do ?? its veryy urgent – user2431829 May 29 '13 at 09:38
-1

That's not possible. You need to read up on the difference between client-side and server-side. This is a really good post:

https://softwareengineering.stackexchange.com/questions/171203/what-are-the-difference-between-server-side-and-client-side-programming

Community
  • 1
  • 1
CodingIntrigue
  • 75,930
  • 30
  • 170
  • 176
  • so do you know how to accomplish that ??? Its veryy urgent and important .... – user2431829 May 29 '13 at 09:35
  • Like I said, you can't do that. The `int b` has already been processed on the server, the only way you can get that javascript variable into the JSP page is to return it back to the server, either via querystring or form post. To explain the entire process would be out of the scope of a stack overflow answer. – CodingIntrigue May 29 '13 at 09:39