CS320 Web and Internet Programming Custom Tag Library Chengyu Sun California State University, Los Angeles.

Slides:



Advertisements
Similar presentations
9 Copyright © 2005, Oracle. All rights reserved. Modularizing JavaServer Pages Development with Tags.
Advertisements

8 Copyright © 2005, Oracle. All rights reserved. Creating the Web Tier: JavaServer Pages.
JSP and web applications
CS4273: Distributed System Technologies and Programming I Lecture 11: JavaServer Pages (JSP)
© Yaron Kanza Advanced Java Server Pages Written by Dr. Yaron Kanza, Edited by permission from author by Liron Blecher.
JavaServerPages Some examples. About JSP Java server pages are a combination of html (or xml), java code appearing within tagged regions, and structures.
Java II--Copyright © Tom Hunter. J2EE JSP Custom Tag Libraries.
Internet Technologies 1 Master of Information System Management Java Server Faces Model/View/Controller Design Pattern for Web Development Slides.
WEB1P servintro1 Introduction to servlets and JSP Dr Jim Briggs.
DT211/3 Internet Application Development
CS320 Web and Internet Programming JSP Scripting Elements and Page Directives Chengyu Sun California State University, Los Angeles.
Generate Dynamic Content On Cache Server Master’s Project Proposal by Aparna Yeddula.
Web programming for project students Dr Jim Briggs.
JSP Architecture  JSP is a simple text file consisting of HTML or XML content along with JSP elements  JSP packages define the interface for the compiled.
Web Applications Basics. Introduction to Web Web features Clent/Server HTTP HyperText Markup Language URL addresses Web server - a computer program that.
Java Servlets and JSP.
Introduction to Java web programming Dr Jim Briggs JWP intro1.
Java Enterprise Edition Java Web Development Structure of a web project Introduction to Web Applications The first project Introduction to Java Web Development.
1 CIS336 Website design, implementation and management (also Semester 2 of CIS219, CIS221 and IT226) Lecture 9 JavaServer Pages (JSP) (Based on Møller.
Java for the WWW November 2012Slide Tag Libraries What are they? –Custom libraries Custom tags – see examples in following slides.
OOSSE - OO Review Review session A review of other OO technologies and may be useful for exam (not required for assignment) OO web development philosophy.
Using JavaBeans and Custom Tags in JSP Lesson 3B / Slide 1 of 37 J2EE Web Components Pre-assessment Questions 1.The _____________ attribute of a JSP page.
® IBM Software Group © 2007 IBM Corporation JSP Custom Tags
Introduction to Java Server Pages (JSPs) Robert Thornton.
Chapter 7 Java Server Pages. Objectives Explain how the separation of concerns principle applies to JSP Describe the operation and life-cycle of a JSP.
Which of the options locate the bean equivalent to the following action? (Select three) a request.getAttribute("address"); b request.getParameter("address");
Middleware Technology JavaServer Pages (JSP)
Deploying CFML on J2EE Servers Vince Bonfanti President New Atlanta Communications, LLC.
Struts J2EE web application framework “ Model 2 ” Model View Controller Controller Servlet Key features XML metadata Struts taglib Simplified form validation.
Stanisław Osiński, 2002JSP – A technology for serving dynamic web content Java Server Pages™ A technology for serving dynamic web content Stanisław Osiński,
JAVA SERVER PAGES CREATING DYNAMIC WEB PAGES USING JAVA James Faeldon CS 119 Enterprise Systems Programming.
1 JSP with Custom Tags Blake Adams Introduction Advanced Java Server Pages – Custom Tags Keyterms: - Tag Library Descriptor(TLD) - Tag Libraries.
Fall 2007cs4201 Advanced Java Programming Umar Kalim Dept. of Communication Systems Engineering
CS320 Web and Internet Programming Java Beans and Expression Language (EL) Chengyu Sun California State University, Los Angeles.
COMP 321 Week 11. Overview Lab 8-1 Solution Tag Files Custom Tags Web Application Deployment.
Chapter 7 Using Custom Tag Libraries and the JSP Standard Tag Library.
JSP Tag Libraries Lec Last Lecture Example We incorporated JavaBeans in “Course Outline” Example But still have to write java code inside java.jsp.
COMP 321 Week 10. Overview Using Beans in JSP Expression Language JSTL Lab 10-1 Introduction Exam Review.
A seminar on j2ee by saritha. s. What is J2EE J2EE (Java 2 Platform, Enterprise Edition) is a Java platform designed for the mainframe-scale computing.
JavaServer Page by Antonio Ko. Overview ► Introduction ► What is a servlet? ► What can servlets do? ► Servlets Vs JSP ► Syntax ► Samples ► JavaBean ►
JSP Custom Tags. Prerequisites Servlet API Mapping to JSP implicit objects JavaServer Pages Basic syntax Implementation via servlet API XML.
JSP Pages. What and Why of JSP? JSP = Java code imbedded in HTML or XML –Static portion of the page is HTML –Dynamic portion is Java Easy way to develop.
JSP BASICS AND ARCHITECTURE. Goals of JSP Simplify Creation of dynamic pages. Separate Dynamic and Static content.
CS320 Web and Internet Programming Introduction to Java Servlets Chengyu Sun California State University, Los Angeles.
JAVA BEANS JSP - Standard Tag Library (JSTL) JAVA Enterprise Edition.
Basic JSP Celsina Bignoli Problems with Servlets Servlets contain –request processing, –business logic –response generation all lumped.
COMP9321 Web Application Engineering Semester 2, 2015 Dr. Amin Beheshti Service Oriented Computing Group, CSE, UNSW Australia Week 3 1COMP9321, 15s2, Week.
Java Web 应用开发: J2EE 和 Tomcat 蔡 剑, Ph.D.. 本讲内容 Web 层技术 (III) Custom Tags JSP and XML JSTL.
Modern Programming Language. Web Container & Web Applications Web applications are server side applications The most essential requirement.
1 Java Server Pages A Java Server Page is a file consisting of HTML or XML markup into which special tags and code blocks are inserted When the page is.
Chapter 6 Chapter 6 Server Side Programming (JSP) Part 1 1 (IS 203) WebProgramming (IS 203) Web Programming.
 Java Server Pages (JSP) By Offir Golan. What is JSP?  A technology that allows for the creation of dynamically generated web pages based on HTML, XML,
JSP JavaServer Pages. What is JSP? Java based technology that simplifies the development of dynamic web sites JSP pages are HTML pages with embedded code.
Java Programming: Advanced Topics 1 Building Web Applications Chapter 13.
10 Copyright © 2004, Oracle. All rights reserved. Building ADF View Components.
® IBM Software Group © 2007 IBM Corporation JSP Tag Files
J2EE JSP Custom Tag Libraries 1 3 JSP: Custom Tag Libraries.
17 Copyright © 2004, Oracle. All rights reserved. Integrating J2EE Components.
CS320 Web and Internet Programming Web Application and MVC Chengyu Sun California State University, Los Angeles.
CS320 Web and Internet Programming Custom Tag Library Chengyu Sun California State University, Los Angeles.
1 Web Programming with Servlets & JSPs WEB APPLICATIONS – AN OVERVIEW.
CS320 Web and Internet Programming Introduction to Java Servlets Chengyu Sun California State University, Los Angeles.
CS3220 Web and Internet Programming Introduction to Java Servlets
CS3220 Web and Internet Programming Custom Tag Library
JSP: Actions elements and JSTL
CS3220 Web and Internet Programming JSP Standard Tag Library (JSTL)
Knowledge Byte In this section, you will learn about:
Pre-assessment Questions
JSP Directives 1-Jan-19.
CS3220 Web and Internet Programming Introduction to Java Servlets
Presentation transcript:

CS320 Web and Internet Programming Custom Tag Library Chengyu Sun California State University, Los Angeles

JSTL Tags ${i}

ASP.NET Tags Enter a number from 1 to 100:

ColdFusion Tags <cftextinput name = “myInput” message = “This field must not be blank” required = “Yes” />

JavaServer Faces (JSF) Tags <h:commandButton action="greeting“ value="#{msg.button_text}" />

What Do These Tags Have in Common Not standard HTML tags  custom tags Interpreted by application server, not browser Generate code and/or HTML text Simpler than code Easier to learn, especially by non-programmers Easier to parse, validate, and interpret by IDEs

Using Custom Tags in JSP Import the tag library Taglib directive URI is an unique identifier of the tag library Reference a tag Library prefix + tag name Example: JSTL Hello

Create Java Custom Tags Implement a tag Using Java code Using a tag file (basically a JSP file) Declare the tag in a Tag Library Descriptor (TLD) file

Example: Add Tag HelloTaglib.jsp AddTag.java cs320.tld

HelloTaglib.jsp prefix="cs320“ uri=" %> Hello Taglib The sum of 1 and 12 is: NOTE: make sure your taglib uri is unique, e.g. have stu## somewhere in the uri.

AddTag.java... package cs320.tag; import java.io.IOException; import javax.servlet.jsp.JspException; import javax.servlet.jsp.JspWriter; import javax.servlet.jsp.tagext.SimpleTagSupport; public class AddTag extends SimpleTagSupport { intop1, op2; public AddTag() { op1 = op2 = 0; }

... AddTag.java public void setOp1( int i ) { op1 = i; } public void setOp2( int i ) { op2 = i; } public void doTag() throws JspException, IOException { JspWriter out = getJspContext().getOut(); out.print( op1+op2 ); }

Tag Library Descriptor (TLD) A Java custom tag must belong to a tag library TLD is an XML document that contains information about a tag library and the tags in the library TLDs are used by application servers and development tools to validate the tags

An Empty TLD <taglib xmlns=" xmlns:xsi=" xsi:schemaLocation=" version="2.1"> 1.0 Hello

Elements of TLD description display-name icon tlib-version short-name uri validator listener tag tag-file function Since JSP 2.1, the order of elements in an TLD must follow the order of the elements in the TLD schema specification.

Declaration for AddTag add cs320.stu31.AddTag empty op1 true op2 true

Elements of name tag-class body-content JSP, scriptless, empty, tagdependent attribute name required rtexprvalue ??

About TLD A TLD file must have the.tld suffix Locations for TLD WAR or unpackaged: WEB-INF or its subdirectories, except WEB-INF/classes and WEB-INF/lib JAR: META-INF or its subdirectories More information about TLD JSP Specification Chapter 15, J2EE 1.4 Tutorial

How Does Server Find a Tag Implementation Custom Tag Tag Library Tag Library uri= " cs320.tld cs320.stu31.AddTag Tag Implementation

A Closer Look at SimpleTagSupport ocs/jsp-2_1- pfd2/javax/servlet/jsp/tagext/SimpleTag Support.html doTag() getJspContext() getJspBody()

Example: RequestInfo Tag Display request information JspContext  PageContext  Request

Example: Cap Tag Capitalize the body content of a tag getJspBody()  JspFragment  invoke(java.io.Writer) ??

Tag Files A way to create a custom tag without writing Java code Tag files – must have.tag suffix WAR or unpackaged: WEB-INF/tags or its subdirectories JAR: META-INF/tags or its subdirectories Tag file in TLD  sometag  /WEB-INF/tags/sometag.tag

Example: Greeting Tag greeting.tag A JSP file No page directive tag and attribute directives Hello Hello, cysun!

EL Functions Just like the function library in JSTL Any static methods can be used as EL functions EL function in TLD 

Example: Leet Talk cs320.tag.Functions String leetTalk( String ) ${cs320:leetTalk(“fear my mad programming skills”)} ph34r my m4d pr0gr4mming zki11z!

Custom Tag vs. Java Bean Custom tags are for the web tier Access to HTTP objects  request, response, context... Good for tasks related to presentation One scope  page Beans are for the business tier No access to HTTP objects  Plain Old Java Object (POJO) Good for tasks related to processing Four scopes  good for sharing data

More Tag Lib Examples Tomcat JSP Examples - /jsp/ /jsp/ JSTL Source code from