|
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.
|