What is the difference between servletConfig and servletContext?
|1.ServletConfig object is one per servlet class.||1.ServletContext object is global to entire web application.|
|2.Object of ServletConfig will be created during initialization process of the servlet.||2.Object of ServletContext will be created at the time of web application deployment.|
|3.In web.xml – <init-param> tag is used to pass configuration data under <servlet-class> tag.||3.In web.xml – <context-param tag is used to pass configuration data under <web-app> tag.|
|4.As long as a servlet is executing, ServletConfig object will be available, it will be destroyed once the servlet execution is completed.||5.As long as web application is executing, ServletContext object will be available, and it will be destroyed once the application is removed from the server.|
Describe implicit objects in jsp.
|Request||The request object provides methods to get HTTP header information such as form data, cookies, HTTP methods etc.|
|response||The response object is used to add cookies , HTTP status codes etc|
|out||JspWriter object is used to send content in a response.|
|session||The session object is used to track session between client requests.|
|application||This object is an instance of servlet context.|
|Config||This object is an instance of servlet config.|
|pageContext||pageContext object stores references to the request and response objects for each request.|
|page||This object is an actual reference to the instance of the page.|
|Exception||The exception object is a wrapper containing the exception thrown from the previous page. It is typically used to generate an appropriate response to the error condition.|
What is the difference between Web server and Application server?
Web server is designed to serve HTTP content whereas Application server is not limited to HTTP response but also can serve other request.
Application server supports distributed transaction and EJB whereas web server only supports servlet and JSP.
Application server can contain web server in them. For example :- JBoss, WAS
Application server provides following features over web server :-
To read more visit Tomcat-web server or application-server
What are different methods of session management in servlets?
As HTTP and Web Server both are stateless, the state of between client and server is managed using additional mechanism which are as:-
What is the difference between include directive and include action?
|Include directive||Include action|
|Resource included by include directive is loaded during jsp translation time.||Resource included by include action is loaded during request/run time.|
|Any change on included resource will not be visible in case of include directive until jsp file compiles again.||While in case of include action any change in included resource will be visible in next request.|
|Syntax of Include directive: <%@ include file="file_name" %>||Syntax of Include action: <jsp:include page="file_name" />|
|When using include action tag we can also pass the parameters to the included page by using param action tag||In case of include directive it is not possible.|
When we use doGet() method & when we use doPost() method in our servlet application?
doGet() method is used when we want to intercept on HTTP GET request. This is actually used to preprocess a request like getting the data from dtatbase and displaying it on html page.
doPost() method is used when we want to intercept HTTP POST request. this is actually used to postprocess the submitted HTML form and displaying/getting the result.
Moreover HTTP GET method sends the parameter/value with URL whereas POST method sends the parameter with headers.
What is the difference between GenericServlet and HttpServlet?
public abstract class GenericServlet extends java.lang.Object implements Servlet, ServletConfig, java.io.Serializable
public abstract class HttpServlet extends GenericServlet implements java.io.Serializable
What is the difference between ServletContext and PageContext?
The ServletContext gives information about the container in which the servlet (or JSP) is running in. Parameters for this can be setup in the web application deployment descriptor and there is one ServletContext per web application.
The PageContext gives the servlet (or JSP) information about the request that it is currently handling and contains information about the request and any parameters, the session, the response object, a reference to the output stream and also a reference to the web application's ServletContext.
What is difference between forward and sendRedirect()?
This method is declared in HttpServletResponse Interface.
This method is used to redirect clienty request to another location for further processing that may be available on different server or different context. This transfer of control task is delegated to the browser by the container. That is, the redirect sends a header back to the browser / client. This header contains the resource url to be redirected by the browser. Then the browser initiates a new request to the given url. Since it is a new request, the old request and response object is lost.
This method is declared in RequestDispatcher Interface.
The method is used to pass the request to another resource within the same server.This process is taken care by web container when we call forward method request is sent to another resource without the client being informed. This is also called server side redirect.
What is difference between page and pagecontext?
Page and Pagecontext are implicit objects in jsp. These are created at JSP translated time. The page object represents the generated servlet instance itself and is used as a scope with in one jsp. Pagecontext is used to initilize all implicit objects for example :- page attributes, access to the request, response and session objects, as well as the JspWriter referenced by out.