JavaBeat
Struts Tutorials | Hibernate Tutorials | JSP Tutorials | Servlet Tutorials | EJB Tutorials | Struts Resources | Spring Resources | Hibernate Resources
JSP Home Articles Resources Tutorials FAQs Forums  

1. Getting familiar with your JSP server

2. Your first JSP

3. Adding dynamic content via expressions

4. Scriptlets

5. Mixing Scriptlets and HTML

6. Directives

7. Declarations

8. Tags

9. Sessions

10. Beans and Forms Processing

11. Tag Libraries

12. Form Editing

13. Log-in pages

14. SQL

15. Sending Email

16. Further learning

JSP Tags

Another important syntax element of JSP are tags.  JSP tags do not use <%, but just the < character.  A JSP tag is somewhat like an HTML tag.  JSP tags can have a "start tag", a "tag body" and an "end tag".  The start and end tag both use the tag name, enclosed in < and > characters.  The end starts with a / character after the < character.  The tag names have an embedded colon character : in them, the part before the colon describes the type of the tag.  For instance:
<some:tag>
body
</some:tag>
If the tag does not require a body, the start and end can be conveniently merged together, as
<some:tag/>
Here by closing the start tag with a /> instead of > character, we are ending the tag immediately, and without a body.  (This syntax convention is the the same as XML.)

Tags can be of two types: loaded from an external tag library, or predefined tags.   Predefined tags start with jsp: characters.  For instance, jsp:include is a predefined tag that is used to include other pages.

We have already seen the include directive.  jsp:include is similar.  But instead of loading the text of the included file in the original file, it actually calls the included target at run-time (the way a browser would call the included target.  In practice, this is actually a simulated request rather than a full round-trip between the browser and the server).  Following is an example of jsp:include usage

<HTML>
<BODY>
Going to include hello.jsp...<BR>
<jsp:include page="hello.jsp"/>
</BODY>
</HTML>
Try it and see what you get.  Now change the "jsp:include" to "jsp:forward" and see what is the difference.  These two predefined tags are frequently very useful. Exercise:  Write a JSP to do either a forward or an include, depending upon a boolean variable (hint:  The concepts of mixing HTML and scriptlets work with JSP tags also!)


Sponsors
Webmaster Hosting Forum
Java Jobs
MyVideoLib
India News
Internet Advances
Latest QnA
Describe the lifecycle of a receiver application in order to receive a message?
Messages are not successful until they have been acknowledged. What are the types of acknowledgments?
What happens to messages if a transaction is rolled back?
What is the Role of the JMS Provider?
What is JMS administered object ?

JavaBeat Media (2004-2008), India
javabeat | planetoss | links directory | advertise
Copyright (2004 - 2008), JavaBeat