Monday, February 18, 2008

**Using JSP tags

There are five main tags:


1. Declaration tag

2. Expression tag

3. Directive tag

4. Scriptlet tag

5. Action tag


1*Declaration tag

<%! %>

*To declare variables or methods.

*Do not generate output so are used with JSP expressions or scriptlets.
eg:
<%!
private int counter = 0 ;

private String get Account ( int accountNo) ;
%>


2*Expression tag

<%= %>

*To embed any Java expression
*It is short for out.println()
*semicolon ( ; ) does not appear at the end of the code
eg;

<%= new java.util.Date() %>


3*Directive tag

<%@ directive ... %>

*To gives special information about the page to the JSP Engine
*three main types of directives:
1)page - processing information for this page.

2)Include - files to be included.

3)Tag library - tag library to be used in this page.


(1)Page directive--optional attributes that provide the
JSP Engine with special processing information



language--Which language the file uses-- <%@ page language = "java" %>


extends--Superclass used by the JSP engine for the translated Servlet.
< %@ page extends = "com.taglib... %>


import-- Import all the classes in a java package into the current JSP page.
This allows the JSP page to use other java classes.
<%@ page import = "java.util.*" %>


info-- Developer uses info attribute to add information/document for a page.
Typically used to add author,version,copyright and date info.
<%@ page info = "http://best-jsp.blogspot.com/,copyright 2008. " %>



(2)Include directive-to include contents of a file inside another
eg:

<%@ include file = "include/privacy.html" %>
or
<%@ include file = "navigation.jsp" %>



4*Scriptlet tag

<% ... %>

*to emmbed any valid Java code is called a Scriptlet
eg:

<%
String username = "BA is the Greatest !" ;

out.println ( username ) ;

%>

No comments: