What is the source code for include() & forwrd() method
servlet program?
Answer Posted / sunny
1. forward should be called before the response has been
committed to the client.
public class Dispatcher extends HttpServlet {
public void doGet(HttpServletRequest req,
HttpServletResponse res) {
RequestDispatcher dispatcher =
request.getRequestDispatcher
("/template.jsp");
if (dispatcher != null) dispatcher.forward
(request, response);
}
}
2. Includes the content of a resource (servlet, JSP page,
HTML file) in the response.
public class Dispatcher extends HttpServlet {
public void doGet(HttpServletRequest req,
HttpServletResponse res) {
RequestDispatcher dispatcher =
getServletContext
().getRequestDispatcher("/banner");
if (dispatcher != null) dispatcher.include
(request, response);
}
}
Is This Answer Correct ? | 0 Yes | 1 No |
Post New Answer View All Answers
How are DOM utilized in JavaScript?
What is a named function in JavaScript? How to define a named function?
How to empty an array in JavaScript?
How to clone an object in javascript?
What data types are supported in Javascript?
What is the reason for wrapping the entire content of a javascript source file in a function book?
Which built-in method returns the characters in a string beginning at the specified location?
Explain the different types of pop-up boxes you can create in JavaScript.
What is the difference between ‘var’ and ‘let’ keyword?
Is javascript a dynamic language?
What is the function of javascript?
Is python better than javascript?
Why is currying called currying?
Does javascript care about whitespace?
How do you check if a value is a number in javascript?