开发者

passing javascript variable value to JSP variable [duplicate]

This question already has an answer here: 开发者_C百科 Closed 10 years ago.

Possible Duplicate:

passing value to JSP via javaScript

i want to pass value of a javascript varible to jsp variable is this possible?


This will require two things:

  1. Your Javascript to somehow post the variable's value, either normally (e.g. in a HTTP POST field) or with AJAX to the web server.
  2. The controller needs to fish it out of the request (there are numerous ways of doing that) and supply it to the JSP.


Well, you can't. Javascript is executed on the browser & what comes out there is only HTML. So you can use javascript to set form fields or send them as request variables using AJAX. You can use your jsp scriplets inside of java script which gets parsed on your server & the values can then be used. for ex:

var i = <%=initialValue%>

When the jsp is processed on the server the scriplets are going to be parsed. What comes out to your browser will be

var i = 10; // In case your initialValue was 10 in your jsp.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜