Showing posts with label JSP Interview Questions and Answers. Show all posts
Showing posts with label JSP Interview Questions and Answers. Show all posts

Thursday, October 8, 2015

JSP Interview Questions and Answers

7.What are the types of scripting elements?
There are three types of scripting elements:
  • Scriptlets
  • Declaration
  • Expression
8. How to create a scriptlet?
Scriptlets are embedded between <% and %> delimiters.
Syntax: <% java code goes in here %>
9. What is declaration element?
  • Declarations are used to declare, define methods and instance variables.
  • Declaration tags does not produce any output that is sent to client.
  • The methods and classes declared will be translated as class level variables and methods during translation.
10. How to declare methods or variables in JSP?
Methods or variables are declared using <%! and %> delimiters.
Syntax: <%! variable=0; %>
11. What is expression element?
Expression element are used to write dynamic content back to the client browser. It is used in place of out.print() method. Only expressions are supported inside the tag. Declarations of methods and variables is not possible inside this tag.

Wednesday, October 7, 2015

JSP Interview Questions and Answers

1. What is a JSP?
JSP files are HTML files with special tags that contain java source code that provide dynamic content. Google search engine, the search page is dynamic will display the search results based on the user’s search request.
2. Compare between Servlet and JSP?
  • In servlets HTML is written inside java code using print statements. In JSP java code is embedded inside HTML.
  • JSP pages are converted to servlets by the web container so actually it can do the same thing as java servlets.
  • JSP are easier for creating HTML content but servlets are easier for writing the java code.
  • A combination of JSP and servlet can be used to separate the presentation(HTML) and logic (java code) and taking the advantage of both.
3. Explain JSP life cycle phases?
JSP life cycle phases are:
  • Translation and compilation: The JSP will be translated into servlet java file and compiled to servlet class by the web container.
  • Instantiation: The web container creates an instance of the servlet class.
  • Initialization: The web container instantiates the servlet and makes it ready for servicing the request.
  • Service: This is the phase during which the JSP services the user requests.
  • Destroy: JSP is destroyed by the web container when the application is uninstalled.
4. Explain JSP life cycle methods?
JSP life cycle methods are:
  • jspInit() – The web container calls the jspInit() to initialize the servlet instance generated. It is invoked before servicing the client request and invoke only once for a servlet instance.
  • _jspService() – The web container invokes the jspService() for each user request, passing it the request and the response objects.
  • jspDestroy() - The web container invokes this when it decides to take the instance out of service.