Last Updated At 2020-06-15
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.
Example of ServletRequest to display the name:index.html- Enter your name
- importservlet.http.*;
- importservlet.*;
- importio.*;
- publicclass DemoServ extends HttpServlet{
- publicvoid doGet(HttpServletRequest req,HttpServletResponse res)
- throwsServletException,IOException
- {
- setContentType("text/html");
- PrintWriter pw=res.getWriter();
- String name=req.getParameter("name");//will return value
- println("Welcome "+name);
- close();
- }}
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:
- public void forward(ServletRequest request, ServletResponse response)throws ServletException, java.io.IOException.
- public void include(ServletRequest request, ServletResponse response)throws ServletException, java.io.IOException.
- publicRequestDispatcher getRequestDispatcher(String resource);