0
Sponsored Links


Ad by Google
In our previous post we have listed JSP Servlet Interview Questions For Freshers Series 1 and now started our next series of JSP Servlet interview questions. Friends you can also contribute us by sharing your interview experience with us, we will post your question here that may be help someone to get in.

JSP Servlet Interview Questions For Freshers Series 2

11. What is the difference between doGet and doPost method?
Below are the few key differences between doGet and doPost method of HttpServlet:
  1. Using doGet method you can send limited amount of data, because data is sent via header. Whereas using doPost method you can send any amount of data because data is sent in a body.
  2. doGet method is not much secure as compare to doPost method because in doGet data is visible in URL whereas in doPost data is not visible in URL.
12. What is the difference between CGI and Servlet?
Here are few key differences between CGI and Servlet:
  • Servlet runs on one Process whereas CGI means each request is equal to a new instance of process.
  • Performance is very fast on Servlet whereas CGI fails to fulfill the performance requirement, because in CGI each request will create a new instance of process whereas Servlet will keep running on only one process with the help of thread.
  • Servlet is only for java whereas CGI can support many languages like Perl, Java etc.

13. Can you list down the life cycle methods of JSP?
  • public void jspInit()
  • public void _jspService(ServletRequest request,ServletResponse)throws ServletException,IOException
  • public void jspDestroy()

14. What are the Scripting tags in JSP
Three scripting tag in JSP:
  • scriptlet tag
  • expression tag
  • declaration tag
15. What is RequestDispatcher in servlet?
The javax.servlet.RequestDispatcher is an interface and it has two methods:
  1. void forward(ServletRequest request,ServletResponse response)throws ServletException,java.io.IOException
  2. void include(ServletRequest request,ServletResponse response)throws ServletException,java.io.IOException
The above methods will used to forward the request to another resource, and also used to include the resource of another servlet to the response of current servlet. With the help of these two method you can also achieve the inter-servlet communication.

16. What are the scope of an Object in JSP?
There are fours scope of an Object in JSP:
  • request scope
  • page scope
  • session scope
  • application scope

17. What is the differences between ServletConfig and ServletContext?
Below are the few key differences between ServletConfig and ServletContext:
  1. ServletConfig object is for per servlet specific whereas ServletContext is for per application.
  2. ServletConfig scope is limited to a particular servlet only whereas ServletContext scope is for application level, In ServletConfig you can set init parameters for a servlet specific whereas in ServletContext you can set init parameter for application.
  3. You can not set attribute in ServletConfig whereas you can set attribute in ServletContext.

18. What is the difference between GenericServlet and HttpServlet
GenericServlet is in javax.servlet package whereas HttpServlet is in javax.servlet.http package.
GenericServlet as it's name implies defines generic, protocol-independent servlet, whereas HttpServlet defines a HTTP protocol specific servlet.

19. How to disable Session in JSP?
You can disable session in JSP page by using below syntax.
<%@ page session="false" %>
20. What is preinitialization of a Servlet?
The process of loading a Servlet before receiving any request is called preinitialization or preloading of a Servlet. By default preinitialization is disable for servlet, you can enable by specifying a <load- on-startup> tag in web.xml file. By default Servlet will initialize only when first request is received. You can load servlet as soon as server get started by specifying <load-on-startup> value as 1. Here is a good example with explanation What is load on startup


Sponsored Links

0 comments:

Post a Comment