Return null JSP

0

Well, I'm having a little problem, but it's getting me down in a simple college exercise.

The intention is only to make a program that receives an amount x and a value y, and multiply it. However, it is to use java methods, and also jsp ..

I did everything right, but my methods are not getting the values typed in the textbox, can anyone help me please?

  

Make a program that receives the quantity and value of three products in the following format:   quantity1 value1 quantity2 value2 quantity3 value3.   The program must calculate these values in the following format:
  TOTAL = Quantity1 * Value1 + Quantity2 * Value2 + Quantity3 * Value3.   Show sub-total and grand total.

Following codes:

HTML:

<html>
    <head>
        <title>Exercicio 1 em jsp</title>
        <meta charset="UTF-8">
        <meta name="viewport" content="width=device-width, initial-scale=1.0">
    </head>
    <body>

        <form name="frm"  action="calcularSoma.jsp" method="post">
            <table border="0" align="center" bordercolor="blue">
                <tr>
                    <td>
                        <b>Quantidade 1:</b>
                    </td>
                    <td>
                        <input type="text" name="txtQtd1" size="2" />  
                    </td>
                    <td>
                        <b>Valor 1:</b>
                    </td>
                    <td>
                        <input type="text" name="txtVlr1" size="2" />  
                    </td>

                </tr>
                <tr>
                    <td>
                        <b>Quantidade 2:</b>
                    </td>
                    <td>
                        <input type="text" name="txtQtd2" size="2" />  
                    </td>
                    <td>
                        <b>Valor 2:</b>
                    </td>
                    <td>
                        <input type="text" name="txtVlr2" size="2" />  
                    </td>

                </tr>
                <tr>
                    <td>
                        <b>Quantidade 3:</b>
                    </td>
                    <td>
                        <input type="text" name="txtQtd3" size="2" />  
                    </td>
                    <td>
                        <b>Valor 3:</b>
                    </td>
                    <td>
                        <input type="text" name="txtVlr3" size="2" />  
                    </td>


                </tr>
                <tr>
                    <td>
                       <input type="submit" value="Calcular" name="acao"> 
                    </td>
                    <td>
                        <input type="reset" value="Limpar">
                    </td>

                </tr>

            </table>
        </form> 
    </body>
</html>

JSP:

<%@page contentType="text/html" pageEncoding="UTF-8" errorPage="jspTrataErra.jsp"%>
<jsp:useBean id="objCalcularSub" class="packageJeanZika.somaTudo"/>
<jsp:setProperty name="objCalcularSub" property="*"/>
<!DOCTYPE html>
<html>

    <head>
        <title>Exercicio</title>
    </head>
    <body>
        <h3>Cálculo</h3>
        <%-- Apresentação dos dados via HTML --%>
        <pre>
           ---------- DADOS OBTIDOS DO BROWSER ---------------------
           Subtotal1 : <%=objCalcularSub.retornaValorSubTotal1()%>
           Subtotal2 : <%=objCalcularSub.retornaValorSubTotal2()%>
           Subtotal3 : <%=objCalcularSub.retornaValorSubTotal3()%>
           ---------------------------------------------------------
           Total geral: <%=objCalcularSub.retornaTotalGeral()%>
           <%-- Total Geral  <%=objSomaNum.RetTotal()%> --%>
           ---------------------------------------------------------
        </pre>
    </body>
</html>

Java:

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
/**
 *
 * @author Jean Cunha
 */
package packageJeanZika;

public class somaTudo {

    private float txtVlr1 ;
    private float txtVlr2 ;
    private float txtVlr3 ;
    private int txtQtd1 ;
    private int txtQtd2 ;
    private int txtQtd3 ;

    public void setVlr1(float txtVlr1) {
        this.txtVlr1 = txtVlr1;
    }

    public void setVlr2(float txtVlr2) {
        this.txtVlr2 = txtVlr2;
    }

    public void setVlr3(float txtVlr3) {
        this.txtVlr3 = txtVlr3;
    }

    public void setQtde1(int txtQtd1) {
        this.txtQtd1 = txtQtd1;
    }

    public void setQtde2(int txtQtd2) {
        this.txtQtd2 = txtQtd2;
    }

    public void setQtde3(int txtQtd3) {
        this.txtQtd3 = txtQtd3;
    }

    public float retornaValorSubTotal1() {

        return txtQtd1 * txtVlr1;
    }

    public float retornaValorSubTotal2() {

        return txtQtd2 * txtVlr2;
    }

    public float retornaValorSubTotal3() {

        return txtQtd3 * txtVlr3;
    }

    public float retornaTotalGeral(){

        return retornaValorSubTotal1() + retornaValorSubTotal2() + retornaValorSubTotal3();
    }

}
    
asked by anonymous 08.05.2015 / 17:21

1 answer

0

If the input is called name="txtQtd1" , your bean must have a method called setTxtQtd1 , but in its code it is called setQtde1 . I saw that the field name in the class is correct txtQtd1, so it must be because you renamed the field and forgot to rename the setter. Some development environments automatically rename getters / setters and others do not ...

Make the same correction for all fields that have names that do not match.

    
08.05.2015 / 17:43