Spring MVC - 如何将数据从 jsp 页面的按钮传递到控制器?

Spring MVC - How to pass data from jsp page's button to Controller?

我在 jsp:

中有一行这样的代码
<button name="CurrentDelete" value="${ra_split}" type="submit">Delete</button>

在我的控制器中我使用:

@RequestParam String CurrentDelete

当我点击删除按钮时,我试图将 ${ra_split} 的值传递给控制器​​,但我得到的只是文本 'Delete' 的值。这是为什么?

这里是解释

If you use the element in an HTML form, Internet Explorer, prior version 8, will submit the text between the and tags, while the other browsers will submit the content of the value attribute.

几天后回到这个问题,我找到了解决办法。

只需使用:

<input type="hidden" value="${ra_split}" name="CurrentDelete">
<input type="submit" value="Delete" />

而不是:

<button name="CurrentDelete" value="${ra_split}" type="submit">Delete</button>

那么问题就解决了,字符串 CurrentDelete 将包含值 ${ra_split} 而不是文本 'Delete'。

我在尝试解决问题时获得的额外信息:

按钮标签:

<button name="CurrentDelete" value="${ra_split}" type="submit">Delete</button>

将始终将按钮标签之间的值传递给控制器​​(在本例中为文本 'Delete'),而不是传递值="${ra_split}"。

要么使用

HttpServletRequest req 

在控制器中然后执行:

String CurrentDelete = req.getParameter("CurrentDelete");

或使用

@RequestParam String CurrentDelete 

在控制器中,

两者都会得到相同的结果。