Directives in JSP

JSP Directives.

A JSP directive affects the overall structure of the servlet class. It usually has the following form:

<% @ directive attribute=”value” %>

There are 3 types of directives:

<% @page…%>-defines page dependent attributes,such as scripting language,error page and buffering reqquirements.

<%@include …%>-includes a file during translation of a page.

<%@taglib…%>-declares a tag library,containing custom actions used in the page.

JSP Actions.

JSP actions use constructs in XML syntax to control the behavior of the servlet engine. You can dynamically insert a file, reuse JavaBeans components, forward the user to another page, or generate HTML for the Java plugin.

There is only one syntax for the Action element, as it conforms to the XML standard:

<jsp:action_name attribute=”value”/>

It is possible to use “import” statements in JSPs, but the syntax is a little different from normal Java.

The first line in the above example is called a “directive”.  A JSP “directive” starts with <%@ characters.

This one is a “page directive”.  The page directive can contain the list of all imported packages.  To import more than one item, separate the package names by commas, e.g.

<%@ page imports=”java.util.*.java.text.*” %>

There are a number of JSP directives, besides the page directive.  Besides the page directives, the other most useful directives are include and taglib.  We will be covering taglib separately.

The include directive is used to physically include the contents of another file.  The included file can be HTML or JSP or anything else — the result is as if the original JSP file actually contained the included text.  To see this directive in action, create a new JSP.

<html>

<body>

going to include hello.jsp…<br>

<%@ include file=”hello.jsp” %>

</body>

</html>

Advertisements

Constructive and genuine appreciation and/or criticism most welcome

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s