Saturday, February 16, 2013

JSP Comments : HTML Comment : JSP Directive : Page Directive : Include Directive : Tag Lib Directive

JSP Comments : HTML Comment : JSP Directive : Page Directive : Include Directive : Tag Lib Directive

JSP Comments

There is only one type of JSP comment available by JSP,

JSP Comment Syntax:

<%-- comment --%>

This JSP comment tag tells the JSP container to ignore the comment part from compilation. That is, the commented part of source code is not considered for the compilation and response.

<%-- This JSP comment part will not be included in the response object --%>

HTML comment

<!-- --> Usually, html comment is used to comment the code snippet, but in actual, it is not good programming habit.

Example :
<!-- This HTML comment part is included in the response object and can be seen in view source -->

// or /* comment */ used inside the <% %> scriplet tag is also not a JSP comment. This is just a java comment and JSP container doesn’t reserve any special treatment for this comments usage.

JSP Directives

JSP Directives extend the basic JSP syntax. Directives are instructions from the JSP to the container that can be used to set the page properties, to import Java classes and packages, and to include external web pages and custom tag libraries. The three directives are:

• Page Directive—The page directive sets the functionality for importing Java classes.
• Include—The include directive sets functionality to include another extenel JSP in your current JSP.
• Taglib—The Taglib directive is used for Custom Tag Libraries.

Page Directive

The page directive has eleven different attributes that control everything from the scripting language to the classes and packages imported into the page.  The general syntax for using a page directive is

<%@ page attribute1="value1" attribute2="value2" ...%>

Except for import, each attribute can be used only once in a page directive. The attribute order is unimportant. The various attributes are listed following:

  • autoflash
  • buffer    
  • contentType
  • errorPage
  • extends
  • import
  • info
  • isErrorPage
  • isThreadSafe
  • following
  • Session

The following examples illustrate some common uses for the page directive:

<%@ page import="java.sql.*" %>
<%@ page import=", java.text.*"%>

Include Directive

The include directive allows you to modularize your web pages and include the entire contents of one file in another. The include directive can be used any number of times in a JSP. The format is,

<%@ include file="file2.jsp" %>

This directive is often used to develop a set of pages that have common features, such as a header, footer, or logo section. By using include, you can have the common code out of your JSP and reuse it. If you modify the headers section (for example), the changes will be applied
immediately to every page that uses the include directive to add the headers file.

Taglib Directive

A tab library is a set of custom tags.  JSP tag libraries are used by web developers who are focused on presenting issues.
The following are the some of the features of JSP custom tags:

•    They can be accessed by all the available objects of JSP page.
•    The response of the generated page can be modified by custom tags by calling the page.
•    Complex interaction can be done with JSP page by nesting the custom tags.


  1. This comment has been removed by the author.

  2. Java Tutorial This is very informative written content in addition to nicely to get a transform. It's good to find out in which a number of people still discover how to produce a quality submit!

  3. delete history I think this is an informative post and it is very useful and knowledgeable. therefore, I would like to thank you for the efforts you have made in writing this thread.

  4. I am very grateful to read your blog.I hope you would provide the great services in the field of website design and development Web Designing Bangalore | Website Designing Bangalore

  5. I am jovial you take pride in what you write. It makes you stand way out from many other writers that can not push high-quality content like you. wiki techno mania wikidot

  6. You have done a great job on this article. It’s very readable and highly intelligent. You have even managed to make it understandable and easy to read. You have some real writing talent. Thank you. Plus d'information

  7. Extraordinary things you've generally imparted to us. Simply continue written work this sort of posts.The time which was squandered in going for educational cost now it can be utilized for studies.Thanks EdTech k12