简体   繁体   English

将参数从JavaScript函数传递到JSP

[英]Pass parameters from JavaScript function to JSP

I need to pass a variable from a javascript function to a jsp page. 我需要将变量从javascript函数传递到jsp页面。 I need to use the parameter in the JSP page for an SQL Query Any way this can be done? 我需要将JSP页面中的参数用于SQL查询可以这样做吗?

Thanks! 谢谢!

the JSP page is generated server side, when Javascript is exectued client side. 当执行Javascript客户端时,JSP页面是在服务器端生成的。 The only way to do that is to have a request (either get or post) sent from the browser to your server with the variable in it. 唯一的方法是从浏览器向服务器发送包含该变量的请求(获取或发布)。 So easiest way, something like <a href="thejsppage.jsp?variablename=addthevalueherewithjavascript">go there</a> . 因此,最简单的方法是,例如<a href="thejsppage.jsp?variablename=addthevalueherewithjavascript">go there</a> You can also do that with a POST request and an hidden field in the form. 您也可以使用POST请求和表单中的隐藏字段来执行此操作。

If you want to avoid reloading the page, you will need to use AJAX. 如果要避免重新加载页面,则需要使用AJAX。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM