I have a form , i want to input numbers one at a time.
I create an object and pass the getParameter() values to it,
<form action="index.jsp" name="form" method="GET">
<input type="text" value="" name="input" />
<input type="hidden" name="hiddenCounter" value="" />
<%
String input = request.getParameter("input");
String hiddenCounter = request.getParameter("hiddenCounter");
control.MainProgram main = new control.MainProgram(input, hiddenCounter);
%>
<input type="submit" value="Submit Numbers" />
<% out.println(main.getResult()); %>
</form>
The constructor in a java class parses the values to int and sets the variables
public MainProgram(String input, String hiddenCounter) {
try {
number = Integer.parseInt(input);
counter = Integer.parseInt(hiddenCounter);
} catch (NumberFormatException e) {
}
}
public int getResult() {
return number;
}
how can i sum up the numbers each time a number is submitted?
The problem is every time the constructor is called it sets the variable to the numbers submitted.
something like
number+=number;
dosent work ( cause its resetting the variable )
ive searched & searched can someone help ?