如何从JavaScript文件中调用servlet

时间:2017-03-15 15:09:11

标签: javascript java jsp servlets

我有以下在index.jsp中创建卡片的功能。我想调用我的servlet传递一个值。但是下面的代码不起作用。当我单击提交按钮时没有任何反应。任何想法?

function creaCard(p){

    var misura='';

    if(p.Taglia==null){
        misura=p.Misura;    
    }else{
        misura=p.Taglia;
    }


    var output = "";

    output += "<div class='col-xs-12 col-sm-4 card'>";
    output += "<div class='panel panel-primary'>";

    output += '<div class="panel-heading">';
    output += "<h2 class='panel-title text-center'>"+p.Abito+"</h2>";
    output += "<h6 class='text-center'>"+p.Quantita+" disponibili</h6>";
    output += "</div>";

    output += '<div class="panel-body">';
    output += "<img class='img-responsive' src='img/"+p.Abito+".jpg' alt='Immagine della "+p.Abito+"'/>" + "<br/>";
    output += "<h5 class=''>Colore: "+p.Colore+"</h5>";
    output += "<h5 class=''>Misura: "+misura+"</h5>";
    output += "<h5 class=''>Prezzo: "+p.Prezzo+" EUR</h5>";


    output += "<form method='post' action='../servletDispatcher'>";
    output += "<input type='hidden' name='funzione' value='mettiCarrello'>";
    output+="<label for='quantitaProdotto'>Numero da acquistare:</label>";
    output += "<select class='form-control' name='quantitaCarrello'>";
    output += "<option value='' disabled selected hidden>scegli...</option>";

    for (i = 1; i <=p.Quantita ; i++) { 
        output+="<option value="+i+">"+i+"</option>";
    }
    output += "</select>";

    output += "<input type='hidden' name='prodottoCarrello' value='"+p.Abito+"'>";
    output += "<input type='hidden' name='prodottoCarrello' value='"+misura+"'>";
    output += "<input type='hidden' name='prodottoCarrello' value='"+p.Colore+"'>";
    output += "<input type='hidden' name='prodottoCarrello' value='"+p.Prezzo+"'>";
    output += "</div>";
    output += '<div class="panel-footer">';
    output += "<button type='submit' class='btn btn-primary'>Metti nel carrello</button>";  
    output += "</div>";
    output += "</form>";
}

0 个答案:

没有答案