Use of request.getRequestDispatcher
## Example This example is for you how to use it.
import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;
public class register extends HttpServlet {
public void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
response.setContentType("text/html");
PrintWriter out = response.getWriter();
String n=request.getParameter("userName");
String p=request.getParameter("userPass");
if(p.equals("servlet"){
RequestDispatcher rd=request.getRequestDispatcher("servlet2");
rd.forward(request, response);
// here servlet2 is get Dispatcher.
}
else{
out.print("Unsucessful!");
RequestDispatcher rd=request.getRequestDispatcher("/index.html");
rd.include(request, response);
}
}
}
It is interface. It provides the facility of dispatching the request to another resource it may be html, servlet or jsp.
## Example This example is for you how to use it.
import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;
public class register extends HttpServlet {
public void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
response.setContentType("text/html");
PrintWriter out = response.getWriter();
String n=request.getParameter("userName");
String p=request.getParameter("userPass");
if(p.equals("servlet"){
RequestDispatcher rd=request.getRequestDispatcher("servlet2");
rd.forward(request, response);
// here servlet2 is get Dispatcher.
}
else{
out.print("Unsucessful!");
RequestDispatcher rd=request.getRequestDispatcher("/index.html");
rd.include(request, response);
}
}
}
No comments:
Post a Comment