program for RequestDispatcher in servlets?
Answers were Sorted based on User's Feedback
Answer / sudhakar
import javax.servlet.*;
import javax.servlet.http.*;
public class TestDispatcher extends HttpServlet throws
IOException, ServletException {
public void doGet(HttpServletRequest request,
HttpServletResponse response) {
RequestDispatcher dispatcher =
request.getRequestDispatcher("/template.jsp");
dispatcher.forward(request, response);
}
}
| Is This Answer Correct ? | 17 Yes | 0 No |
import javax.servlet.*;
import javax.servlet.http.*;
import javax.servlet.http.RequestDispatcher;
public class dispatcher extends HttpServlet throws
IOException, ServletException {
public void doGet(HttpServletRequest request,
HttpServletResponse response) {
RequestDispatcher dis=
request.getRequestDispatcher("welcome.jsp");
dis.forward(request, response);//it will go to ur
desired page.
dis.include("Hello java");//it will display ur
message also to ur desired page.
}
}
| Is This Answer Correct ? | 10 Yes | 5 No |
Answer / avinah kapoor
import javax.servlet.*;
import javax.servlet.http.*;
public class RequestDispatcherDemo extends HttpServlet
{
public void doGet(HttpServletRequest
req,HttpServletResponse res) throws ServletException
{
res.setContentType("text/html");
PrintWriter out=res.getWriter();
RequestDespatcher rd=req.getRequestDispacher("welcome");
rd.forward(req,res);//it forwart the response to
welcome servlet page but cant take resource calling page.
}
}
| Is This Answer Correct ? | 1 Yes | 1 No |
Directive Include and Action Include how both are working in JSP, what is the difference between both?In which suituation we have to choose these elements?
Explain get and post.
What are the Internal servlets maintained by the web server?
How do servlets work?
What are all the protocols supported by httpservlet?
What are the different types of servlets?
What are the types of ServletEngines?
What is the difference between doGet and doPost?
what is the difference between ServletContext and ServletConfig
Difference between get and post in java servlets?
What are different types of SessionTracking?
How many ways to remove the session object in the container