How does the data capture of a form work?

Asked

Viewed 139 times

9

I have this code to get data from a form:

@WebServlet(name = "computador", urlPatterns = {"/computador"})
public class computador extends HttpServlet {

    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        float total = Float.parseFloat(request.getParameter("total"));
        float preco = Float.parseFloat(request.getParameter("preco"));
        float consumo = Float.parseFloat(request.getParameter("consumo"));
    }

}

But I don’t know why he uses the request to get the data instead of the response. And what’s the point of response?

1 answer

8


Request is for sending requests to the server.

Response is the server response to the client.

A web application or system works totally different from a desktop or console where all processing takes place on the local machine.

A web application must obey the http protocol cycle, which works in two times: request and response.

The term request means that the client(a browser for example) is making a request to the server for some resource, be it an html page, image, download etc the server receives and processes the request and returns something may be html, json etc this return takes the name of sponse.

  • And when I will use the Answer.Somethings?

  • When you wish to send something to the customer, in response to a request.

Browser other questions tagged

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