Over the past few days, some of our users reported seeing Doget and Dopost in the sample servlet. The doGet () method is used to get information from the server, and the exact doPost () method is used to send information to the server.
What is the difference between doGet () and doPost () method?
doGet () should be used when sending small amounts of data and therefore insensitive data such as an on-demand request. doPost () should be used when a large amount of sensitive data needs to be sent. Examples are sending data after filling in a status, or sending login ID and details.
You should use
doGet () if you really want to intercept HTTP GET requests. You oweWe use
doPost () whenever we want to intercept HTTP POST requests. It’s all. Never port a new one or vice versa (like here in the failed
processRequest () Netbeans automatically generated method). This makes no sense.
Typically, HTTP requests are idempotent. This means that you generate the same result every time your site makes a request (leaving authorization / authentication and / or the time-sensitive nature of the fan page – search results, recent posts, etc. – gardening consideration). Can we talk about any bookmark request? Click on the link, then on the bookmark, enter the raw url via the browser address bar, and so on, only triggers the HTTP GET request. When the servlet listens normally to the URL in question, its
doGet () method is called. It is usually created to preprocess a request. This means that before serving the html output of the search JSP, you need to do some things to collect the data that will be displayed in the table.
@WebServlet ("/ products")PublicServlet class products extend HttpServlet @EJB private product service product service; @ Crush void doGet protected (HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException List
products = productService.list (); request.setAttribute ("Products", // Products); Will be available as $ products in JSP request.getRequestDispatcher ("/ WEB-INF / products.jsp"). forward (request, response);
Note that the specific JSP file is explicitly placed in the
/ WEB-INFfolder so that end users cannot directly access it without using the preprocessing servlet (and thus gaining a lot, when you see an empty table).
What are doGet () and doPost () methods develop and explain a servlet that handles an HTTP POST request?
Like the doGet () method, the do Post () procedure is called by the server through the Organization () method to process an HTTP POST request. In doGet (), the path parameters are appended to the url, and in do Post (), the structure parameters are sent separately from the network in the body of the HTTP request.