Science  People  Locations  Timeline
Index: A B C D E F G H I J K L M N O P Q R S T U V W X Y Z

Home > JavaServer Pages


 

JSP or JavaServer Pages is a Java technology that allows developers to dynamically generate HTML, XML or some other type of web page. The technology allows Java code and certain pre-defined actions to be embedded into static content.

The JSP syntax adds additional XML tags, called JSP actions, to be used to invoke built-in functionality. Additionally, the technology allows for the creation of JSP tag libraries that act as extensions to the standard HTML or XML tags. Tag libraries provide a platform independent way of extending the capabilities of a web server.

JSPs are compiled into Servlets by a JSP compiler. A JSP compiler may generate a servlet in Java code that is then compiled by the Java compiler, or it may generate byte code for the servlet directly. In either case, it is helpful to understand how the JSP compiler transforms the page into a Java servlet. For an example, see the following input, and its resulting generated Java servlet.

1 JSP Syntax

A JavaServer Page may be broken down into the following pieces:

1.1 Static Data

Static data is written out to the HTTP response exactly as it appears in the input file. Thus a valid JSP input would be a normal HTML with no embedded java or actions. In that case, the same data would be sent in the response each and every time by the web server. Of course, the point of JSP is to allow dynamic data to be inserted into the static content.

1.2 JSP Directives

JSP directives control how the JSP compiler generates the servlet. The following directives are available:

    <%@ include file="somefile.ext" %>

import results in a java import statement being inserted into the resulting file
contentTypespecifies the content that is generated. This should be used if HTML is not used or if the character set is not the default character set.
errorPageindicates the page that will be shown if an exception occurs while processing the HTTP request.
isErrorPageif set to true, it indicates that this is the error page.
isThreadSafeindicates if the resulting servlet is threadMany programming languages, operating systems, and other software development environments support what are called threads of execution. Threads are similar to processes, in that both represent a single sequence of instructions executed in parallel with o safe.

    <%@ page import="java.util.*" %> //example import     <%@ page contentType="text/html" %> //example contentType     <%@ page isErrorPage=false %> //example for non error page     <%@ page isThreadSafe=true %> //example for a thread safe JSP

Note: Only the "import" directive can be used multiple times in the same JSP.

    <%@ taglib prefix="myprefix" uri="taglib/mytag.tld" %>

Read more »

Non User