Tell me more ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

This question already has an answer here:

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"

  %>
share|improve this question
add comment

marked as duplicate by Quentin, Łukasz L., graphicdivine, fotanus, jszumski May 29 at 13:29

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

2 Answers

Try Writing the JavaScript variable in the page itself using Expression tag

<script type="text/javascript">

var myVariable=<%= a %>;
alert(a); //will show you the value
</script>

To access the javascript variable in server side code, You need to send it as part of POST Data.

You can use a Hidden field and assign the value and later you can access the same using Request.getParameter("hiddenName") in server code

share|improve this answer
 
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 at 9:38
 
@user2431829, updated my answer –  Murali May 29 at 9:41
add comment

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

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

share|improve this answer
 
so do you know how to accomplish that ??? Its veryy urgent and important .... –  user2431829 May 29 at 9: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. –  RGraham May 29 at 9:39
add comment

Not the answer you're looking for? Browse other questions tagged or ask your own question.