Double Bonanza Offer - Upto 30% Off + 1 Self Paced Course Free | OFFER ENDING IN: 0 D 0 H 0 M 0 S

Log In to start Learning

Login via

Post By Admin Last Updated At 2020-06-15
Servlet Request Interface

Servlet Request Interface:

A challenge of ServletRequest is used to give the client request information to a servlet, for instance, content sort, content length, parameter names and qualities, header informations, attributes.

Servlet Request Interface Methods

Example of ServletRequest to display the name:index.html
  1. Enter your name
DemoServ.java
  1. importservlet.http.*;
  2. importservlet.*;
  3. importio.*;
  4. publicclass DemoServ extends HttpServlet{
  5. publicvoid doGet(HttpServletRequest req,HttpServletResponse res)
  6. throwsServletException,IOException
  7. {
  8. setContentType("text/html");
  9. PrintWriter pw=res.getWriter();
  10. String name=req.getParameter("name");//will return value
  11. println("Welcome "+name);
  12. close();
  13. }}

RequestDispatcher:

A challenge of ServletRequest is used to give the client request information to a servlet, for instance, content sort, content length, parameter names and qualities, header informations, attributes.

Methods of RequestDispatcher interface:
  1. public void forward(ServletRequest request, ServletResponse response)throws ServletException, java.io.IOException.
  2. public void include(ServletRequest request, ServletResponse response)throws ServletException, java.io.IOException.
forward( ) method:forward( ) methodInclude( ) method:include ( ) methodSyntax of getRequestDispatcher method:
  1. publicRequestDispatcher getRequestDispatcher(String resource);