如何将值从javascript传递到struts2中的java类? [英] how can i pass value from javascript to a java class in struts2?
本文介绍了如何将值从javascript传递到struts2中的java类?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
function redirect(id){
alert(id);
document.forms["AddToCart"].submit();
}
这是我的javascript。如何将'id'的值传递给AddToCart.java。我正在使用struts2框架。
This is my javascript. How can i pass the value of 'id' into AddToCart.java. I am using struts2 framework.
推荐答案
您可以将值存储在表单内的隐藏字段中,因此在提交表单时该值将发送给Action。
You can store the value in a hidden field inside your form and so when the form is submitted the value will be sent to Action.
<form name="AddToCart" ... >
...
<input type="hidden" id="myid"/>
.....
</form>
然后
function redirect(id){
document.getElementById('myid').value = id;
document.forms["AddToCart"].submit();
}
这篇关于如何将值从javascript传递到struts2中的java类?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文