• Skip to main content
  • Skip to primary sidebar
  • Skip to secondary sidebar
  • Skip to footer

Computer Notes

Library
    • Computer Fundamental
    • Computer Memory
    • DBMS Tutorial
    • Operating System
    • Computer Networking
    • C Programming
    • C++ Programming
    • Java Programming
    • C# Programming
    • SQL Tutorial
    • Management Tutorial
    • Computer Graphics
    • Compiler Design
    • Style Sheet
    • JavaScript Tutorial
    • Html Tutorial
    • Wordpress Tutorial
    • Python Tutorial
    • PHP Tutorial
    • JSP Tutorial
    • AngularJS Tutorial
    • Data Structures
    • E Commerce Tutorial
    • Visual Basic
    • Structs2 Tutorial
    • Digital Electronics
    • Internet Terms
    • Servlet Tutorial
    • Software Engineering
    • Interviews Questions
    • Basic Terms
    • Troubleshooting
Menu

Header Right

Home » Servlet » Examples » Servlet for handling HTTP POST request Example
Next →
← Prev

Servlet for handling HTTP POST request Example

By Dinesh Thakur

Like doGet () method, the do Post () method is invoked by server through service () method to handle HTTP POST request. The doPost () method is used when large amount of data is required to be passed to the server which is not possible with the help of doGet () method.

 

In doGet () method, parameters are appended to the URL whereas, in do Post () method parameters are sent in separate line in the HTTP request body. The do Get ( ) method is mostly used when some information is to be retrieved from the server and the doPost () method is used when data is to be updated on server or data is to be submitted to the server. To understand the working of do Post () method, let us consider a sample program to define a servlet for handling the HTTP POST request.

A program to define a servlet for handling HTTP POST request

import java.io.*;

import java.util.*;

import javax.servlet.*;

public class ServletPostExample extends HttpServlet

{

    public void doPost(HttpServletRequest req, HttpServletResponse res) throws ServletException, IOException

   {

      PrintWriter out = res.getWriter();

      String login= req.getParameter(“loginid”);

      String password= req.getParameter(“password”);

      out.println(“Your login ID is: “);

      out.println(login);

      out.println(“Your password is: “);

      out.println(password);

      out.close();

   }

}

The corresponding HTML code for this servlet is as follows

<HTML>

          <BODY>

                  <CENTER>

                         <FORM NAME=”Form1″ METHOD=”post” ACTION=”https://ecomputernotes.com:8080/ServletGetExample”>

                                 <B>Login ID</B> <INPUT TYPE=”text” NAME=”loginid” SIZE=”30″>

                                 <P>

                                 <B>Password</B> <INPUT TYPE=”password” NAME=”password” SIZE=”30″>

                                 </P>

                                 <P>

                                 <INPUT TYPE=submit VALUE=”Submit”.>

                                 </P>

           </BODY>

</HTML>

This HTML code create as web page containing a form

Enter the required data and press the submit button on the web page. The browser will display the response generated dynamically by the corresponding servlet.

You’ll also like:

  1. Servlet for handling HTTP GET request Example
  2. How Servlet handling multiple post Requests
  3. Servlets Client HTTP Request
  4. HTTP Post Method
  5. What happens when our servlet program gets first or Other than First Request from browser window?
Next →
← Prev
Like/Subscribe us for latest updates     

About Dinesh Thakur
Dinesh ThakurDinesh Thakur holds an B.C.A, MCDBA, MCSD certifications. Dinesh authors the hugely popular Computer Notes blog. Where he writes how-to guides around Computer fundamental , computer software, Computer programming, and web apps.

Dinesh Thakur is a Freelance Writer who helps different clients from all over the globe. Dinesh has written over 500+ blogs, 30+ eBooks, and 10000+ Posts for all types of clients.


For any type of query or something that you think is missing, please feel free to Contact us.


Primary Sidebar

Servlet Tutorials

Servlet Tutorials

  • Servlet - Home
  • Servlet - Types
  • Servlet - Advantages
  • Servlet - Container
  • Servlet - API
  • Servlet - Chaining
  • Servlet - Life Cycle
  • Servlet - Developement Way
  • Servlet - Servlet Vs CGI
  • Servlet - Server Side
  • Servlet - HttpServletRequest
  • Servlet - Cookies Advantages
  • Servlet - JDBC Architecture
  • Servlet - HttpServlet
  • Servlet - HttpServletResponse
  • Servlet - Web Technology
  • Servlet - Applet Communication
  • Servlet - Html Communication
  • Servlet - HTTP POST Request
  • Servlet - HTTP GET Request

Other Links

  • Servlet - PDF Version

Footer

Basic Course

  • Computer Fundamental
  • Computer Networking
  • Operating System
  • Database System
  • Computer Graphics
  • Management System
  • Software Engineering
  • Digital Electronics
  • Electronic Commerce
  • Compiler Design
  • Troubleshooting

Programming

  • Java Programming
  • Structured Query (SQL)
  • C Programming
  • C++ Programming
  • Visual Basic
  • Data Structures
  • Struts 2
  • Java Servlet
  • C# Programming
  • Basic Terms
  • Interviews

World Wide Web

  • Internet
  • Java Script
  • HTML Language
  • Cascading Style Sheet
  • Java Server Pages
  • Wordpress
  • PHP
  • Python Tutorial
  • AngularJS
  • Troubleshooting

 About Us |  Contact Us |  FAQ

Dinesh Thakur is a Technology Columinist and founder of Computer Notes.

Copyright © 2025. All Rights Reserved.

APPLY FOR ONLINE JOB IN BIGGEST CRYPTO COMPANIES
APPLY NOW