L14-JSPTags - Session 14 JSP Custom Tags Session 14 JSP...

Info iconThis preview shows pages 1–6. Sign up to view the full content.

View Full Document Right Arrow Icon
Session 14 – JSP Custom Tags 11/2/2010 1 © Robert Kelly, 2001-2010 Session 14 JSP Custom Tags 1 Reading & Reference Reading Note that Head First covers both the JSP 2.0 approach and the Head First – Pages 476-490 Chapter 10 (pages 512-528, 576-577) Java EE Tutorial - Chap 8 and Chap 5 (pages 172-174) java.sun.com/javaee/5/docs/tutorial/doc/JavaEETutorial.pdf Di i f JSP 2 0 h (i l d l l “classic” approach – this lecture covers mostly the JSP 2.0 approach © Robert Kelly, 2001-2010 2 Discussion of JSP 2.0 approach (includes class example) http://www.sitepoint.com/article/jsp-2-simple-tags Note that the Java EE tutorial contains the most recent documentation
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Session 14 – JSP Custom Tags 11/2/2010 2 © Robert Kelly, 2001-2010 Reference Reference Sun JSP / Tag API java.sun.com/j2ee/sdk_1.3/techdocs/api/index.html java.sun.com/javaee/5/docs/api/ © Robert Kelly, 2001-2010 3 The 1.3 API covers the classic approach Lecture Objectives Understand how to abstract JSP control logic into a custom tag Learn how a tld is used to: define the interface of a tag (name, attributes, and type) Specify the Java class that implements the tag Learn the life cycle of the custom tag © Robert Kelly, 2001-2010 4 Learn to use the JSP 2.0 Become familiar with differences between JSP 2.0 approach and classic tag approach
Background image of page 2
Session 14 – JSP Custom Tags 11/2/2010 3 © Robert Kelly, 2001-2010 Web Architecture Web layer Data sources Clients JSP Page Bean Custom Tag XML JDBC EJB servlet © Robert Kelly, 2001-2010 5 JSP Page Why Do We Need Custom Tags? Java Beans Allow you to store and retrieve data, independent of the JSP, Are easy to implement, and but, they Are not good for implementing complex logic and Cannot manipulate JSP conten © Robert Kelly, 2001-2010 6 Cannot manipulate JSP content
Background image of page 3

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Session 14 – JSP Custom Tags 11/2/2010 4 © Robert Kelly, 2001-2010 JSP Custom Tags A JSP Custom Tag is similar to a bean in that both are Java objects that are used with JSPs (beans for data and tags for control) A JSP Custom Tag is an XML tag that (when encountered in a JSP page) causes specific Java code to be executed © Robert Kelly, 2001-2010 7 Think of a custom tag as the correct approach to follow when you think you need a scriptlet Using a Custom Tag in Your JSP Refer to the tag using the XML qualified element name notation In <c:out value="${p.key}“ /> , c is the namespace and out is the tag name The c library is referred to in your JSP taglib directive <%@ taglib prefix=“c” uri=“http://java.sun.com/jsp/jstl/core” %> This is a name, not a location © Robert Kelly, 2001-2010 8 The taglib refers to a tld, a file that 1. maps the names in the libraries to classes 2. contains the rules of the tag (e.g., attribute names)
Background image of page 4
Session 14 – JSP Custom Tags 11/2/2010 5 © Robert Kelly, 2001-2010 TLD (Tag Library Descriptor) File must use .tld extension tld located in WEB-INF Class files public Class MyTagHandler { . ..
Background image of page 5

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Image of page 6
This is the end of the preview. Sign up to access the rest of the document.

Page1 / 19

L14-JSPTags - Session 14 JSP Custom Tags Session 14 JSP...

This preview shows document pages 1 - 6. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online