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

How can I add one to the integer each time I hit the submit button?

1 Answer 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" />
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.