用户登录
用户注册

分享至

如何将值从 javascript 传递到 struts2 中的 java 类?

  • 作者: 楓27110021
  • 来源: 51数据库
  • 2022-10-21

问题描述

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();
}
软件
前端设计
程序设计
Java相关