<input type="text" name="integer" value="0"/>
<input type="submit" value="add one" />
<%
String integer = request.getParameter("integer");
%>
<%
int x = 0;
try { x = Integer.parseInt("integer"); }
catch (Exception e) { x = 0; }
%>
每次点击提交按钮时,如何在整数中添加一个?
答案 0 :(得分:2)
<%
String integer = request.getParameter("integer");
int x = (integer == null ? 0 : (Integer.parseInt(integer) + 1));
%>
<input type="text" name="integer" value="<%=x%>"/>
<input type="submit" value="add one" />