Visualizzazione dei risultati da 1 a 2 su 2
  1. #1
    Utente di HTML.it
    Registrato dal
    Nov 2001
    Messaggi
    525

    [java] restituzione variabili da servlet

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

  2. #2
    Utente di HTML.it L'avatar di floyd
    Registrato dal
    Apr 2001
    Messaggi
    3,837
    le stringhe si confrontano con equals
    if (submit.equals("Prev")) {

Permessi di invio

  • Non puoi inserire discussioni
  • Non puoi inserire repliche
  • Non puoi inserire allegati
  • Non puoi modificare i tuoi messaggi
  •  
Powered by vBulletin® Version 4.2.1
Copyright © 2024 vBulletin Solutions, Inc. All rights reserved.