Signup · Login
Stardeveloper.com  
Home · Tutorials · Forums · Web Hosting Plans · Faisal Khan's Blog · Contact
Search Stardeveloper.com
Stardeveloper RSS Feed
Newsletter
Enter your email address below to be informed every time a new article is posted at Stardeveloper.com:

You can follow Faisal Khan on Twitter
Article Categories
.NET  .NET
  ASP (16)
  ASP.NET (41)
  ADO (16)
  ADO.NET (10)
  COM (6)
  Web Services (4)
  C# (1)
  VB.NET (3)
  IIS (2)

J2EE  J2EE
  JSP (15)
  Servlets (9)
  Web Services (1)
  EJB (4)
  JDBC (4)
  E-Commerce (1)
  J2ME (1)
  Products (1)
  Applets (1)
  Patterns (1)
Log In
UserName Or Email:

Password:

Auto-Login:

Miscellaneous Links
  Submit Article

Hosted by Securewebs.com
 
Home : J2EE : JSP : Introducing Scripting Variables in JSP Tags
 

Then we write some HTML text to the client between the star:secondtag tags. Within the tags we also write the time variable's value out to the user. See! we neither declared nor initialized the time scripting variable. It was done for us by the JSP tag which also set it's value to current date and time.

<star:secondtag>
	<p align="center">Date value retrieved from JSP Tag : 
		<%= time %></p>
</star:secondtag>

Now run this JSP page using some URL like http://localhost:8080/web/jsp/SecondTag.jsp and you should see the JSP page showing you current date and time.

To see the online demo, click here.

Summary
In this step by step tutorial we learned that scripting variables are page-level variables which are declared and instantiated by JSP tags. We then created a JSP tag which declares single scripting variable time for us. To make that JSP tag we had to go through following steps :

  • Created main SecondTag class which implements Tag interface.
  • Created SecondTagTEI class which extends TagExtraInfo class and overrides it's getVariableInfo() method to return an array of VariableInfo objects. In our case we returned a single VariableInfo object for our time variable.
  • Created DemoTags.tld Tag Library Descriptor File. In the <tag> tag, we used another tag, <teiclass> to point to our SecondTagTEI class, a must if you want to declare variables from JSP tags.
  • Created SecondTag.jsp JSP page which called the tag library and showed a live demo for secondtag JSP tag.

Then we write some HTML text to the client between the star:secondtag tags. Within the tags we also write the time variable's value out to the user. See! we neither declared nor initialized the time scripting variable. It was done for us by the JSP tag which also set it's value to current date and time.

<star:secondtag>
	<p align="center">Date value retrieved from JSP Tag : 
		<%= time %></p>
</star:secondtag>

Now run this JSP page using some URL like http://localhost:8080/web/jsp/SecondTag.jsp and you should see the JSP page showing you current date and time.

To see the online demo, click here.

Summary
In this step by step tutorial we learned that scripting variables are page-level variables which are declared and instantiated by JSP tags. We then created a JSP tag which declares single scripting variable time for us. To make that JSP tag we had to go through following steps :

  • Created main SecondTag class which implements Tag interface.
  • Created SecondTagTEI class which extends TagExtraInfo class and overrides it's getVariableInfo() method to return an array of VariableInfo objects. In our case we returned a single VariableInfo object for our time variable.
  • Created DemoTags.tld Tag Library Descriptor File. In the <tag> tag, we used another tag, <teiclass> to point to our SecondTagTEI class, a must if you want to declare variables from JSP tags.
  • Created SecondTag.jsp JSP page which called the tag library and showed a live demo for secondtag JSP tag.

Previous ( 2 Gone )( No Further Pages )

See all comments and questions (post-ad) posted for this tutorial.


Related Articles
  1. Building Your first custom JSP Tag

Comments/Questions ( Threads: 2, Comments: 5 )
    Contains 1 or more replies by the Author of this Article.
    Contains 1 or more replies by Faisal Khan.

  1. BAD STRUCTURE ( 3 Replies )
  2. Path to be given

Post Comments/Questions

In order to post questions/comments, you must be logged-in. If you are not a member yet, then signup, otherwise login. Once you login then come back to this page and you'll see a form right here which will allow you to post comments/questions.

Please note, one of the benefits of signing up is to be notified immediately by email everytime you receive a reply to the thread you have subscribed to.

 
© 1999 - 2009 Stardeveloper.com, All Rights Reserved.