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 类?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:如何将值从 javascript 传递到 struts2 中的 java 类?
基础教程推荐
- 无法复制:“比较方法违反了它的一般约定!" 2022-01-01
- Spring AOP错误无法懒惰地为此建议构建thisJoinPoin 2022-09-13
- 存储 20 位数字的数据类型 2022-01-01
- Struts2 URL 无法访问 2022-01-01
- 如何对 Java Hashmap 中的值求和 2022-01-01
- 使用堆栈算法进行括号/括号匹配 2022-01-01
- 修改 void 函数的输入参数,然后读取 2022-01-01
- 问题http://apache.org/xml/features/xinclude测试日志4j 2 2022-01-01
- REST Web 服务返回 415 - 不支持的媒体类型 2022-01-01
- RabbitMQ:消息保持“未确认"; 2022-01-01
