How to make the back-end and front-end connection?

Asked

Viewed 333 times

-1

I need your help. I have an HTML form, which requests two types of data from the user, Height and Weight. And I have a code in Java that will receive these two data and calculate the BMI. My question is how can I make the connection between the back end and the front end ? I already have the Tomcat 9.0 server running integrated in Eclipse Java EE.

HTML form:

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Calculador de IMC</title>
    <link rel="stylesheet" href="style.css">
</head>
<body>
    <section class="content">
        <div class="formulario">
            <h1>Calculador de IMC</h1>
            <hr>
            <h2>Digite seu peso e altura.</h2>
            <form class="forms" method="POST" action="receber.jsp">
                Peso: <input class="caixa" name="peso">
                Altura: <input class="caixa" name="altura">
                <input class="send" type="submit" value="Enviar"> 
            </form>
        </div>  
    </section>
</body>
</html>

IMC calculation in Java:

        String peso = request.getParameter("peso");
        String altura = request.getParameter("altura");
        double peso1 = Double.parseDouble(peso);
        double altura1 = Double.parseDouble(altura);

        double imc = peso1/(altura1*altura1);
        System.out.printf(" IMC  = %.2f %n",  imc );
              
        if (imc < 18.5) {
        System.out.println("Classificação: Magreza");
        System.out.println("Você precisa de uma dieta hipercalórica.");
        }

        if (imc >= 18.5 & imc < 25 ) {
        System.out.println("Classificação: Normal");
        System.out.println("Você precisa de uma dieta normocalórica.");
        }

        if (imc >= 25 & imc < 30 ) {
            System.out.println("Classificação: Sobrepeso");
            System.out.println("Você precisa de uma dieta hipocalórica.");
        }

        if (imc > 30 ) {
            System.out.println("Classificação: Obesidade ");
            System.out.println("Você precisa de uma dieta hipocalórica.");
        }
  • Hello. Study about Servlets and JSP (Javaserver Pages).

  • All right, I was already researching around this subject, I will continue studying. Thank you for the comment!

1 answer

0


basically creating the receive.jsp page that will receive the POST variables and you decide what to do with them.

I use php, but jsp tbm is server side language

Browser other questions tagged

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