无法通过按钮使用url检索从jsp传递到控制器的值 [英] unable to retrieve the passed value from jsp to controller using url via a button
本文介绍了无法通过按钮使用url检索从jsp传递到控制器的值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我将href分配给按钮并将值传递给控制器
I am assigning href to a button and passing a value to the controller
-
JSP页面
JSP page
<td><a href="viewController?book_id=<%=vo.getBookId()%>"><input type="button" name="remove" value="DELETE"/></a>
</td>
在控制器中,我尝试使用以下方法来单击按钮时获取值:
In controller, I am trying to get the value when the button is clicked using:
if(request.getParameter("remove") !=null)
{
int cart_id=(Integer)request.getSession(false).getAttribute("cartid");
b_id = (String) request.getParameter("book_id");
int bid=Integer.parseInt(b_id);
System.out.println(bid);
}
这虽然我在URL中传递了book_id
值,但仍打印了一个空值.
我想知道如何通过按钮在URL中传递值.
This prints a null value though I have passed book_id
value in the URL.
I want to know how can I get the value passed in the URL via the button.
推荐答案
您不能将[a]标记与这样的[input]标记结合使用. 尝试使用带有隐藏输入的表单:
You can't combine [a] tag with an [input] tag like that. Try using a form instead with hidden inputs:
<form action=viewController>
<input type=hidden name=remove value=delete>
<input type=hidden name=book_id value=<%=vo.getBookId()%>>
<input type=submit value='Delete'>
</form>
结果网址为:viewController?remove=delete&book_id=...
这篇关于无法通过按钮使用url检索从jsp传递到控制器的值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文