html - take 5 numbers one at a time from a form in a jsp page and calculate the average with a java class? -



html - take 5 numbers one at a time from a form in a jsp page and calculate the average with a java class? -

i have form , want input numbers 1 @ time.

i create object , pass getparameter() values 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 java class parses values int , sets variables

public mainprogram(string input, string hiddencounter) { seek { number = integer.parseint(input); counter = integer.parseint(hiddencounter); } grab (numberformatexception e) { } } public int getresult() { homecoming number; }

how can sum numbers each time number submitted?

the problem every time constructor called sets variable numbers submitted.

something

number+=number;

dosent work ( cause resetting variable )

ive searched & searched can help ?

if you're not worried multi-threaded access, can declare number static.

the variable bound control.mainprogram class rather instance.

you then...

try { number += integer.parseint(input);

... declare getresult static well...

... invoke <% out.println(control.mainprogram.getresult()); %>

note doesn't give average, title implies - gives sum.

but it's simple plenty implement average in body of static int getresult method.

java html jsp parseint getparameter

Comments

Popular posts from this blog

formatting - SAS SQL Datepart function returning odd values -

c++ - Apple Mach-O Linker Error(Duplicate Symbols For Architecture armv7) -

php - Yii 2: Unable to find a class into the extension 'yii2-admin' -