在我的一个迷你在线书店的代码中,我有一行重复5次的'name‘参数值
<input name="JSP-2" type="submit" value="Buy">单击按钮Buy时,应用程序将重定向到一个文件buy.jsp,在该文件中它将获取name的值并显示图书的相应详细信息。
在我的buy.jsp中,我包含了
<% String bname= request.getParameter("name");
out.print(bname);
%>但是名称没有分配给bname,它将值显示为null。如何从提交类型输入传递参数?请帮帮忙。
发布于 2010-09-26 18:02:17
您必须在请求中传递参数。因为您有一个表单,并且正在提交表单,所以您可以在表单中有一个名为"submitType“的隐藏字段,并在单击按钮时使用javascript填充它。那么这将在下一个请求中可用。
在表单中的某个位置:
<input type="hidden" name="submitType">
在提交按钮中:
<input name="JSP-2" type="submit" onclick="setType('Buy')">
Javascript: formName是表单的名称
<script>
function setType(type)
{
//formName is the name of your form, submitType is the name of the submit button.
document.forms["formName"].elements["submitType"].value = type;
//Alternately, you can access the button by its Id
document.getElementById("submitId").value = type;
}
</script>https://stackoverflow.com/questions/3797285
复制相似问题