java 环境变量、tomcat 环境变量配置
JSP获取客户端IP地址

表单传值错误

Jimmy posted @ 2012年2月21日 00:19 in JSP+MySQL , 1302 阅读

使用图片作为按钮,点击按钮后都跳转到同一页面,

此时如何判断用户点击的是哪个图片呢?

隐藏标签可以帮上忙了,下面代码中可以使用id来传递value值“next”.在跳转之后的页面中可以使用request.getParameter("id")来获取所要传递的参数值。

<form name="tonext" action="factAssess.jsp" method="post">
	<input type="hidden" name="id" value="next"/>
  	<input type="image" src="next.png" name="nextButton"></input>
</form>

可是要传递的是一个java类型的变量怎么办?自然是:

<% out.print("<td><input type=\"hidden\" name=\"factId\" value='"+factId+"'</input></td>");%>

在这里忘了变量factId需要加上引号'"+factId+"',在跳转后的页面中factId的String值可以正确获取,而使用Integer.parseInt(request.getParameter("factId"))来获取factId的int值总是会出现“Integer parseint NumberFormatException”,花了很长时间才找到错误所在。

Avatar_small
gmail email login 说:
2020年6月03日 03:28

Email is one of most used features when you work, why don't learn more about it such as how to create a templates for your email, create signatures or set alarm to send later... with the tutorials on gmail email login


登录 *


loading captcha image...
(输入验证码)
or Ctrl+Enter