Return calculation to jsp with a Servlet

Asked

Viewed 52 times

0

Good afternoon, I have just graduated in computer science and I’m looking to enter the area of programming. I still have a lot of doubts in web programming but I’m already starting to develop some small portfolios.

That being said, I want to do a little application that takes some values on a jsp page, take these values in a class that I created, do the processing and then use a Servlet to show calculation, like this:

    <input type="text" name="valor1"/>
    <input type="text" name="valor2"/>
    <input type="button" name="calcular" value="Calcular"/>
</body>```

receber o valor1 e 2 digitado pelo usuário e calcular a soma por exemplo

classe no java:

```public class Teste {

    private double valor1;
    private double valor2;

    public double getValor1() {
        return valor1;
    }

    public void setValor1(double valor1) {
        this.valor1 = valor1;
    }

    public double getValor2() {
        return valor2;
    }

    public void setValor2(double valor2) {
        this.valor2 = valor2;
    }
    
    public Double soma() {
        return valor1 + valor2;
    }
}```

Pergunta 1: Como eu faço o binding do meu jsp com a minha classe java?
Pergunta 2: Como ficaria o servlet?

```public class TesteComServlet extends HttpServlet {
    
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

    }```
No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.