JavaServer Pages

JavaServer Pages (JSP) are server-side Java EE components that generate responses, typically HTML pages, to HTTP requests from clients. JSPs embed Java code in an HTML page by using the special delimiters <% and %>. A JSP is compiled to a Java servlet, a Java application in its own right, the first time it is accessed. After that, the generated servlet creates the response.

The following would be a valid for loop in a JSP page:


\begin{lstlisting}
<p>Counting to three:</p>
<% for (int i=1; i<4; i++) { %>
<p>This number is <%= i %>.</p>
<% } %>
<p>OK.</p>
\end{lstlisting}

The output displayed in the user's web browser would be:


\begin{lstlisting}
Counting to three:
\par
This number is 1.
\par
This number is 2.
\par
This number is 3.
\par
OK.
\end{lstlisting}