What is the difference between ServletConfig and ServletContext?
ServletConfig is used for sharing init parameters specific to a servlet while ServletContext is for sharing init parameters within any Servlet within a web application.
What does request getRequestDispatcher do?
The RequestDispatcher interface provides the facility of dispatching the request to another resource it may be html, servlet or jsp. This interface can also be used to include the content of another resource also. It is one of the way of servlet collaboration.
How do you make a RequestDispatcher object?
How to Create an Object of RequestDispatcher?
- RequestDispatcher requestDispatcher=ServletContext. getRequestDispatcher(String path); Description:
- RequestDispatcher requestDispatcher=ServletContext. getNamedDispatcher(String name);
- RequestDispatcher requestDispatcher=request. getRequestDispatcher(“String path”);
What are ServletConfig?
ServletConfig is an object containing some initial parameters or configuration information created by Servlet Container and passed to the servlet during initialization. ServletConfig is for a particular servlet, which means one should store servlet-specific information in web. xml and retrieve them using this object.
What is difference between doGet and doPost?
doGet() shall be used when small amount of data and insensitive data like a query has to be sent as a request. doPost() shall be used when comparatively large amount of sensitive data has to be sent. Examples are sending data after filling up a form or sending login id and password.
Why do you use servlet?
A servlet is a Java programming language class that is used to extend the capabilities of servers that host applications accessed by means of a request-response programming model. Although servlets can respond to any type of request, they are commonly used to extend the applications hosted by web servers.
What is inter servlet communication?
What is Inter-Servlet Communication. A process where two or more servlets communicates with each other to process the client request. A servlet can forward the request to another servlet to process the client request. A servlet can include the output of another servlet to process the client request.
Why do we use ServletConfig?
ServletConfig object is created by web container for each servlet to pass information to a servlet during initialization. This object can be used to get configuration information from web. xml file. when to use : If you want to share information to all sevlet, it a better way to make it available for all servlet.
How do I find ServletConfig?
Example of ServletConfig to get all the initialization parameters
- import java.io.IOException;
- import java.io.PrintWriter;
- import java.util.Enumeration;
- import javax.servlet.ServletConfig;
- import javax.servlet.ServletException;
- import javax.servlet.http.HttpServlet;
- import javax.servlet.http.HttpServletRequest;
What is requestdispatcher in servlet?
In Servlet RequestDispatcher is an interface that defines an object in the servlet that receives a request from the client and sends it to any resources such as JSP, HTML, or any servlet on the server. The serverlet container is responsible for making the object of RequestDispatcher. It is used to include the response of one servlet into another.
How do I get the response of a second servlet?
As you can see in the above figure, response of second servlet is included in the response of the first servlet that is being sent to the client. The getRequestDispatcher () method of ServletRequest interface returns the object of RequestDispatcher.
What are the two methods defined in the requestdispatcher interface?
There are two methods defined in the RequestDispatcher interface. The RequestDispatcher interface provides two methods. They are: public void forward (ServletRequest request,ServletResponse response)throws ServletException,java.io.IOException: Forwards a request from a servlet to another resource (servlet, JSP file, or HTML file) on the server.
What is the use of getrequestdispatcher url?
request.getRequestDispatcher (“url”) means the dispatch is relative to the current HTTP request.Means this is for chaining two servlets with in the same web application Example RequestDispatcher reqDispObj = request.getRequestDispatcher (“/home.jsp”);