1
<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; }
%>

每次点击提交按钮时,如何将整数加一?

4

1 回答 1

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" />
于 2013-03-04T23:19:50.470 回答