How to pass a parameter in URL on a form submit in Struts2(如何在 Struts2 中提交表单的 URL 中传递参数)
问题描述
我正在 Struts2 中做一个项目,我需要在 URL 中设置一个参数,例如下面链接中的用户参数.
I am doing a project in Struts2 where I need of setting a parameter in URL like user parameter in below link.
我希望在单击表单提交按钮时传递此参数,而不是单独传递任何链接.我知道如何使用 <s:url> 做到这一点,但这样我需要创建一个链接而不是表单提交.
I want this parameter to be passed when I click a form submit button and not any links separately. I know how to do this with <s:url> but that way I need to create a link instead of form submit.
有人可以帮我提供一个代码示例如何做到这一点吗?我知道有一种方法可以使用 HTML 或 Struts1 来实现,但是如何使用 Struts2 来实现呢?如果在 struts.xml 中有办法做到这一点,请举例说明.
Can someone please help me with a code sample how to do this?
I know there's a way to do it with HTML or Struts1 but how to do it with Struts2? If there is a way to do this in struts.xml, please explain with an example.
<form action="/example/xyz.action?user=george" method="POST">
推荐答案
试试这个:
<s:form action="xyz.action" method="GET">
<s:hidden name="user" value="george"/>
// other fields
</s:form>
method="GET" 将在 url 上显示您的参数,<s:hidden name="user" value="george"/> 将采用你的参数.
method="GET" will show your parameter on the url, <s:hidden name="user" value="george"/> will take your parameter.
这里也是一个例子例子
这篇关于如何在 Struts2 中提交表单的 URL 中传递参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:如何在 Struts2 中提交表单的 URL 中传递参数
基础教程推荐
- 使用堆栈算法进行括号/括号匹配 2022-01-01
- RabbitMQ:消息保持“未确认"; 2022-01-01
- 如何对 Java Hashmap 中的值求和 2022-01-01
- 无法复制:“比较方法违反了它的一般约定!" 2022-01-01
- 修改 void 函数的输入参数,然后读取 2022-01-01
- REST Web 服务返回 415 - 不支持的媒体类型 2022-01-01
- Struts2 URL 无法访问 2022-01-01
- 存储 20 位数字的数据类型 2022-01-01
- Spring AOP错误无法懒惰地为此建议构建thisJoinPoin 2022-09-13
- 问题http://apache.org/xml/features/xinclude测试日志4j 2 2022-01-01
