A Brief Overview of Java Server Page (JSP) programming

JSP has four predefined variables:

request

the HttpServletRequest object


response

the HttpServletResponse object


out

PrintWriter object used to send output to client


session

HttpSession object associated with request



JSP includes four scripting elements:

JSP page directive
<%@ page import="java.util.*" %>


The main use of a JSP page directive is to include imports for the compiler.


JSP declaration
<%! private int accessCount=0; %>

A JSP declaration is used to define, and possibly initialize, a variable. The declaration is executed only the first time the .jsp page is executed (after translation).


JSP expression
<%= new Date() %>


A JSP "expression" is used to insert a value directly into the output. The expression
is evaluated, converted to a String, and inserted into the page.


JSP scriptlet

<%
String wordList=(String) session.getAttribute("wordList");
if(wordList==null)
{
  out.println("wordList is empty");
}
else
{
  out.println(wordList);
}
%>

A JSP "scriptlet" is a block of Java code that will be executed.