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


Please Help Members By Posting Answers For Below Questions

How are DOM utilized in JavaScript?

858


What is a named function in JavaScript? How to define a named function?

717


How to empty an array in JavaScript?

742


How to clone an object in javascript?

725


What data types are supported in Javascript?

724


What is the reason for wrapping the entire content of a javascript source file in a function book?

767


Which built-in method returns the characters in a string beginning at the specified location?

813


Explain the different types of pop-up boxes you can create in JavaScript.

728


What is the difference between ‘var’ and ‘let’ keyword?

694


Is javascript a dynamic language?

667


What is the function of javascript?

690


Is python better than javascript?

624


Why is currying called currying?

641


Does javascript care about whitespace?

682


How do you check if a value is a number in javascript?

683