In this example, we are going to implement posting massage to servlet. In the following program, you will learn how to post massage.
The following program uses getOutputStream() method. This is the method that defines an object to assist a servlet in sending a response to the client . The servlet container creates a ServletResponse object and passes it as an argument to the servlet's service method. ServletOutputStream is a constructor. This constructor provides an output stream for sending data to the client. A ServletOutputStream object is created using response.getOutputStream() method. The servlet extends the HttpServlet and overrides the doGet() method which is inherited from HttpServlet class. The server invokes doGet() method whenever web server receives the GET request from the servlet.
In this example we are going to make one html in which we post the massage given by user. The controller will check if the username , password and comment entered by the user is blank then servlet will display massage null, if the username, password and comment entered by the user are not blank then servlet will display the massage entered by the user.
Html file for this program:
Here is the code of this program:
xml file of this program.
|<?xml version="1.0" encoding="ISO-8859-1"?>
PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
Output of this program.
If you enjoyed this post then why not add us on Google+? Add us to your Circles
Liked it! Share this Tutorial