Home Tutorial Jsp JSP Components

 
 

Share on Google+Share on Google+
JSP Components
Posted on: November 22, 2012 at 12:00 AM
Advertisement
In this section we will discuss about the elements of JSP.

JSP Components

In this section we will discuss about the elements of JSP.

Structure of JSP Page :

JSPs are comprised of standard HTML tags and JSP tags. The structure of JavaServer pages are simple and easily handled by the servlet engine. In addition to HTML ,you can categorize JSPs as following -

  • Directives
  • Declarations
  • Scriptlets
  • Comments
  • Expressions

Directives :

A directives tag always appears at the top of your JSP file. It is global definition sent to the JSP engine. Directives contain special processing instructions for the web container. You can import packages, define error handling pages or the session information of the JSP page. Directives are defined by using <%@ and %> tags.

Syntax -

<%@ directive attribute="value" %>

Declarations :

This tag is used for defining the functions and variables to be used in the JSP. This element of JSPs contains the java variables and methods which you can call in expression block of JSP page. Declarations are defined by using <%! and %> tags. Whatever you declare within these tags will be visible to the rest of the page.

Syntax - 

 <%! declaration(s) %>

Scriptlets:

In this tag we can insert any amount of valid java code and these codes are placed in _jspService method by the JSP engine. Scriptlets can be used anywhere in the page. Scriptlets are defined by using <% and %> tags.

Syntax -

 <% Scriptlets%>

Comments :

Comments help in understanding what is actually code doing. JSPs provides two types of comments for putting comment in your page. First type of comment is for output comment which is appeared in the output stream on the browser. It is written by using the <!-- and --> tags.

Syntax -

 <!-- comment text -->

Second type of comment is not delivered to the browser. It is written by using the <%-- and --%> tags.

Syntax -

  <%-- comment text --%>

Expressions :

Expressions in JSPs is used to output any data on the generated page. These data are automatically converted to string and printed on the output stream. It is an instruction to the web container for executing the code with in the expression and replace it with the resultant output content. For writing expression in JSP, you can use <%= and %> tags.

Syntax -

<%= expression %>

Advertisement

Related Tags for JSP Components :


Follow us on Twitter, or add us on Facebook or Google Plus to keep you updated with the recent trends of Java and other open source platforms.

Posted on: November 22, 2012

Recommend the tutorial

Advertisements Advertisements
 

 

 

DMCA.com