But you can check it to the database also that we will see in the development chapter. In this program, we are cheking for hardcoded information. If password is servlet, it will forward the request to the WelcomeServlet, otherwise will show an error message: sorry username or password error!. ![]() In this example, we are validating the password entered by the user. Rd.forward(request, response) //method may be include or forward servlet2 is the url-pattern of the second servlet RequestDispatcher rd=request.getRequestDispatcher("servlet2") The getRequestDispatcher() method of ServletRequest interface returns the object of RequestDispatcher. How to get the object of RequestDispatcher Response of the first servlet is not displayed to the user.Īs you can see in the above figure, response of second servlet is included in the response of the first servlet that is being sent to the client. public void include(ServletRequest request,ServletResponse response)throws ServletException,java.io.IOException:Includes the content of a resource (servlet, JSP page, or HTML file) in the response.Īs you see in the above figure, response of second servlet is sent to the client.public void forward(ServletRequest request,ServletResponse response)throws ServletException,java.io.IOException:Forwards a request from a servlet to another resource (servlet, JSP file, or HTML file) on the server.The RequestDispatcher interface provides two methods. There are two methods defined in the RequestDispatcher interface. It is one of the way of servlet collaboration. This interface can also be used to include the content of another resource also. ![]() The RequestDispatcher interface provides the facility of dispatching the request to another resource it may be html, servlet or jsp.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |