我在jsp中有一行这样的代码:
<button name="CurrentDelete" value="${ra_split}" type="submit">Delete</button>
在我的控制器中,我使用:
@RequestParam String CurrentDelete
当我点击“删除”按钮时,我试图将$ {ra_split}的值传递给Controller,但我得到的只是文本的值&#39;删除&#39;代替。那是为什么?
答案 0 :(得分:0)
以下是解释
如果您使用HTML表单中的元素,Internet Explorer(早期版本8)将在和标记之间提交文本,而其他浏览器将提交value属性的内容。
答案 1 :(得分:0)
几天后我回到这个问题,我想出了一个解决方案。
只需使用:
<input type="hidden" value="${ra_split}" name="CurrentDelete">
<input type="submit" value="Delete" />
而不是:
<button name="CurrentDelete" value="${ra_split}" type="submit">Delete</button>
然后问题将得到解决,String CurrentDelete将包含值$ {ra_split}而不是文本'Delete'。
我在尝试解决问题时获得的额外信息:
按钮标记:
<button name="CurrentDelete" value="${ra_split}" type="submit">Delete</button>
将始终将按钮标记之间的值传递给Controller(在本例中为文本“Delete”),而不是传递值=“$ {ra_split}”。
使用
HttpServletRequest req
在Controller中然后执行:
String CurrentDelete = req.getParameter("CurrentDelete");
或使用
@RequestParam String CurrentDelete
控制器中的,
会得到相同的结果。