La querystring dell'url che riceve la servlet č:
?month_num=0&year_now=05&submit=Next
Il problema č che nella pagina web in cui visualizzo le variabili (hello.vm) la variabile test ha sempre valore 0 mentre dovrebbe aumentare o diminuire in base al valore del submit nel form.
I valori delle altre variabili, che non sono elaborati, vengono passati correttamente....
public class HelloTest extends VelocityServlet {
int num_month_now;
public Template handleRequest( HttpServletRequest request,
HttpServletResponse response,
Context context ) {
Template template = null;
String submit = request.getParameter("submit").trim();
String month_now = request.getParameter("month_now");
int new_month_now=0;
if (submit == "Prev"){
int num_month_now = Integer.parseInt(month_now);
new_month_now = num_month_now - 5;
}
else if (submit == "Next"){
int num_month_now = Integer.parseInt(month_now);
new_month_now = num_month_now + 5;
}
String test = Integer.toString(new_month_now);
try {
context.put("name", "Velocity Test");
context.put("submit", submit);
context.put("test", test);
template = Velocity.getTemplate("hello.vm");
} catch( Exception e ) {
System.err.println("Exception caught: " + e.getMessage());
}
return template;
}
}