Exforsys.com
 

Sponsored Links

 

JSP Tutorials

 
Home Tutorials JSP
 

JSP Tags

 
Category: JSP
Comments (2)

JSP Tags

In this JSP tutorial, you will learn about JSP tags, list of the tags used in Java Server Pages, declaration tag, general syntax of declaration tag, expression tag and general syntax of expression tag.



Tags are a vital concept in Java Server Pages (JSP). Below is a list of tags used in JSP. This section discusses Declaration Tag and Expression Tag in detail; syntax, usage with examples and explanations for both.


List of the tags used in Java Server Pages:

  • Declaration tag
  • Expression tag
  • Directive tag
  • Scriptlet tag
  • Action tag

.


Syntax, usage and example of Declaration Tag and Expression Tag:


Declaration tag:

Declaration tag is used to define functions, methods and variables that will be used in Java Server Pages.


Notation of the Declaration tag is shown below:


<%! %>


At the start of Declaration tag one must place <%!  Inside Declaration tag one can declare variables or methods. Declaration tag ends with the notation %>. Also care must be taken to place a semicolon that is ; at the end of each code placed inside Declaration tag.


General syntax of Declaration Tag:


<%!                //start of declaration tag
    
statement1;
     statement2;   //variables or methods declaration
    
..........;
     ..........;
%>                 //end of declaration tag



For example:



<%!
    
private int example = 0 ;
    
private int test = 5 ;
%>



Expression tag:

Expression tag is used to display output of any data on the generated page. The data placed in Expression tag prints on the output stream and automatically converts  data into string. The Expression tag can contain any Java expression used for printing output equivalent to out.println().Thus, an expression tag contains a scripting language expression which is evaluated, automatically converts data to a String and the outputs are displayed.


Notation of Expression tag is shown below:


<%= %>



Expression tag must begin with <%= Inside Expression tag, the user embeds any Java expression. Expression tag ends with the notation %>.


NOTE: Expression should not contain a semicolon between codes, as with Declaration tag.


General syntax of Expression Tag:


<%!                  //start of declaration tag
    

     statement
       //Java Expression
    

%>
                   //end of declaration tag   



For example:



<%!                 
    

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



%>
                  



Above example displays current date and time as  Date() is placed inside the Expression tag <%= %>



Read Next: JSP Directives



 
Related Topics


 

Comments


Deepa Anand said:

  Itz very informative
May 11, 2007, 4:39 am

Iftikhar Ahmed said:

  Dear Sir,
JSP Tages are not enough. You need to improve details of related topics.

Directive Elements
– Provides global control of JSP ……..……………..
􀂃 Scripting Elements
– JSP comments ……………………………………...
– declarations ……………………………………...
• Used to declare instance variables & methods
– expressions ……………………………………...
• A java code fragment which returns String
– scriptlets ……………………………………...
• Blocks of java code
􀂃 Action Elements
– Special JSP tags ……..……………………………..

regards
July 15, 2007, 11:29 pm

Post Your Comment:

Members Please Login
Your Name:*
e-mail ID:(required for notification)*
Image Verification: 
 
 Subscribe    

Sponsored Links

 

Subscribe via RSS


Get Daily Updates via Subscribe to Exforsys Free Training via email


Get Latest Free Training Updates delivered directly to your Inbox...

Enter your email address:


 

Subscribe to Exforsys Free Training via RSS
 

 
Partners -  Privacy and Legal Policy -  Site News -  Contact   Sitemap  

Copyright © 2000 - 2010 exforsys.com. All Rights Reserved

Page copy protected against web site content infringement by Copyscape