AI & Machine Learning
Servlet Request Interface
Last updated on Jun 15, 2020
Copy Link:
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- <form action="welcome"method="get">
- Enter your name<input type="text"name="name"><br>
- <input type="submit"value="login">
- </form>
- 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.
Include( ) method:
Syntax of getRequestDispatcher method:
- publicRequestDispatcher getRequestDispatcher(String resource);

