隐藏从jsp传递到struts2动作类的参数

2022-01-16 00:00:00 parameter-passing jquery java jsp struts2
<s:url action="someAction" var="act">
<s:param name="param1">value1</s:param>
</s:url>
<s:a href="%{act}">Go Action</s:a>

通过点击 Go Action 链接,地址将为 www.example.com/someAction?param1=value1我想在提交表单时隐藏传递的参数(param1=value1),例如 method="POST".无论如何我可以做到吗?谢谢.

By clicking Go Action link, the address will be www.example.com/someAction?param1=value1 I want to hide passed parameters (param1=value1) like method="POST" in submitting of form. Is there anyway I can do it? Thanks.

推荐答案

要隐藏传递的参数,实际上需要提交表单.您应该阻止 click 事件的默认行为并将其替换为 form 事件.像本例那样做

To hide passed parameter actually you need to submit the form. You should prevent the default behavior of the click event and replace it with the form event. Do it like in this example

<s:form id="f1" action="someAction">
  <s:hidden name="param1" value="value1"/>
  <s:url action="someAction" var="act"/>
  <s:a id="a1" href="%{act}">Go Action</s:a>
  <script type="text/javascript">
    $(document).ready(function() {
      $("#a1").click(function(event) {
        event.preventDefault();
        $("#f1").submit();
      });
    });
  </script>
</s:form>

相关文章