program for RequestDispatcher in servlets?

Answers were Sorted based on User's Feedback



program for RequestDispatcher in servlets?..

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

program for RequestDispatcher in servlets?..

Answer / sonam

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

program for RequestDispatcher in servlets?..

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

Post New Answer

More Servlets Interview Questions

How servlets are deployed in java?

0 Answers  


hi.... i have problem in running of servlet. i am using Tomcat server in my pc.. The problem is when i am click on strat it will display like below FAIL - Application at context path /first could not be started.. How i can slove the problem.. help plz

3 Answers  


What are the life cycle methods of a servlet?

0 Answers  


What is http servlet? Explain with the help of an example.

0 Answers  


How servlet is created?

0 Answers  


What is HTTP Tunneling?

1 Answers   Wipro,


What are the ways to handle multi-threading in servlets?

0 Answers  


What are the uses of servlet and what is servlet chaining?

0 Answers  


What is done after deploying a war file and before client gives a request

2 Answers   Bosch,


In which cases Destroy() is invoked?

2 Answers  


What’s the difference between sendredirect and forward methods

0 Answers  


My Question is that i am using <image> tag in my servlet and after compilation after that calling by url in my browser then images are not showing. Sometime images are showing and sometime is not showing. I am using Tomcat to run my servlets. Tell me if there any specification for image in servlets or what is solution for this ??

2 Answers  


Categories