spring - Pass get values to method and call in jsp page -
i'm using spring mvc, making small web-app. have form in jsp page, , i'm trying pass values .get controller method , display results called method after pressing "submit" button on same jsp page or another, preferrably on same page.
this how form looks like: http://i65.tinypic.com/6gyo02.png
this method want called after getting values form:
public void calcmacros() { int goal = 0; if (this.goal == 0.7){ goal = 1; } else if (this.goal == 0.9) { goal = 2; } else if (this.goal == 1) { goal = 3; } else if (this.goal == 1.2){ goal = 4; } switch (goal) { case 1: weightloss(); weightlossprotcalc(); weightlosscarbcalc(); weightlossfatcalc(); break; case 2: weightloss(); weightlossprotcalc(); weightlosscarbcalc(); weightlossfatcalc(); break; case 3: tdeecalculator(); maintainproteincalc(); maintaincarbcalc(); maintainfatcalc(); break; case 4: weightgain(); weightgainprotcalc(); weightgaincarbcalc(); weightgainfatcalc(); break; default: break; } system.out.println("selected goal " + goal + "and proper methods have been called."); }
best question be, how can transform method .post controller can display it's results in same jsp page. how call method/controller in jsp page?
thank you!
edit: controller
@requestmapping(value = "/calculator" , method = requestmethod.get) public string calculatorpage(modelmap model, macrocalculatorform macrocalculatorform) { model.addattribute("user",getprincipal()); macrocalculatorform.calcmacros(); return "calculator"; }
would it, or should rewrite method want called controller?
you should have 2 methods in @controller
:
(1) 1 method supports get
: provide display view
of first page (before calculations).
(2) 1 method supports post
: process inputs received first page , sending results view (jsp) back.
Comments
Post a Comment