JSP

JavaServer Pages (JSP) is a Java technology that helps software developers serve dynamically generated web pages based on HTML, XML, or other document types.
Directives:
Directives provide general information about the JSP page to the JSP engine. There are three types of directives: page, include, and taglib.
A page directive informs the engine about the overall properties of a JSP page. For example, the following page directive informs the JSP engine that we will be using Java as the scripting language in our JSP page:
   <%@ page language="java" %>
An include directive tells the  JSP engine to include the contents of another file (HTML, JSP , etc.) in the current page. Here is an example of an include directive:
   <%@ include file="copyright.html" %>
A taglib directive is used for associating a prefix with a tag library. The following is an example of a taglib directive:
   <%@ taglib prefix="test" uri="taglib.tld" %>
Declarations:
Declarations declare and define variables and methods that can be used in the  JSP page.
The following is an example of a JSP declaration:
<%! int count = 0; %>
This declares a variable named count and initializes it to 0. The variable is initialized only once when the page is first loaded by the JSP engine, and retains its value in sub-sequent client requests. That is why the count variable in listing 10.1 is not reset to 0 each time we access the page.


A declaration always starts with <%! and ends with %>. It can contain any number of valid Java declaration statements. For example, the following tag declares a variable and a method in a single tag:


<%!
       String color[] = {"red", "green", "blue"}; 
       String getColor(int i)
       {
          return color[i];
       }
   %>

JSP Interview Questions