Java Web 应用开发: J2EE 和 Tomcat 蔡 剑, Ph.D.. 本讲内容 Web 层技术 (III) Custom Tags JSP and XML JSTL.

Slides:



Advertisements
Similar presentations
J0 1 Marco Ronchetti - Web architectures – Laurea Specialistica in Informatica – Università di Trento Java XML parsing.
Advertisements

J0 1 Marco Ronchetti - Basi di Dati Web e Distribuite – Laurea Specialitica in Informatica – Università di Trento.
Enterprise Java: Developing JSP Custom Tag Libraries Developing JSP Custom Tag Libraries O'Reilly Conference on Enterprise Java, March 2001.
9 Copyright © 2005, Oracle. All rights reserved. Modularizing JavaServer Pages Development with Tags.
8 Copyright © 2005, Oracle. All rights reserved. Creating the Web Tier: JavaServer Pages.
JSP and Servelets.
JSP and web applications
© Yaron Kanza Advanced Java Server Pages Written by Dr. Yaron Kanza, Edited by permission from author by Liron Blecher.
Java II--Copyright © Tom Hunter. J2EE JSP Custom Tag Libraries.
Advanced Java Server Pages An more detailed look at JSPs.
Internet Technologies 1 Lecture 1 Introduction.
JSP Tag Extensions And Java Bean. JSP Tag Extensions Tag extensions look like HTML (or rather, XML) tags embedded in a JSP page. They have a special meaning.
DT211/3 Internet Application Development
Generate Dynamic Content On Cache Server Master’s Project Proposal by Aparna Yeddula.
Object-Oriented Enterprise Application Development JavaServer Pages Tag Libraries.
Xpath Sources:
CSE 6331 © Leonidas Fegaras XML Tools1 XML Tools Leonidas Fegaras.
17 Apr 2002 XML Programming: JAXP Andy Clark. Java API for XML Processing Standard Java API for loading, creating, accessing, and transforming XML documents.
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.
1 XML at a neighborhood university near you Innovation 2005 September 16, 2005 Kwok-Bun Yue University of Houston-Clear Lake.
Basic Elements JSP For a Tutorial, see:
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.
Chapter 111© copyright Janson Industries 2011 Custom Tags ▮ Tag Handlers ▮ XML ▮ Tag Libraries ▮ Web Deployment Descriptor.
® IBM Software Group © 2007 IBM Corporation JSP Custom Tags
1 JSP 1.2 Custom Tags. 2 Agenda ● What is and why custom tags? ● Components that make up custom tag architecture ● How to create custom tags? ● How does.
Custom Tags1 Usage Rules PowerPoint slides for use only in for-credit courses at degree-granting institutions Slides can be modified.
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.
Jakarta Struts Presented by Object Computing, Inc. (OCI) Written by Greg Elliott
Deploying CFML on J2EE Servers Vince Bonfanti President New Atlanta Communications, LLC.
SDPLNotes 3.3: DOM Examples1 3.3 DOM Examples 1. DOM processing in a Web browser –a toy "XML database browser" –with JavaScript and MS Internet Explorer.
Java Web 应用开发: J2EE 和 Tomcat 蔡 剑, Ph.D.. 本讲内容 EJB 层技术 (II) Transaction and Security Resource Connection Deployment Web Services.
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,
Slides © Marty Hall, book © Sun Microsystems Press 1 JSP Scripting Elements Core Servlets & JSP book:
XML Processing in Java. Required tools Sun JDK 1.4, e.g.: JAXP (part of Java Web Services Developer Pack, already in Sun.
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
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 Fundamentals Elements of a JSP Using Beans with JSP Integrating Servlets and JSP.
CSC 2720 Building Web Applications JavaServer Pages (JSP) The Basics.
JSP Tag Libraries Lec Last Lecture Example We incorporated JavaBeans in “Course Outline” Example But still have to write java code inside java.jsp.
CS320 Web and Internet Programming Custom Tag Library Chengyu Sun California State University, Los Angeles.
Document Object Model DOM. Agenda l Introduction to DOM l Java API for XML Parsing (JAXP) l Installation and setup l Steps for DOM parsing l Example –Representing.
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.
Schema Data Processing
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.
1 Introduction JAXP. Objectives  XML Parser  Parsing and Parsers  JAXP interfaces  Workshops 2.
© FPT SOFTWARE – TRAINING MATERIAL – Internal use 04e-BM/NS/HDCV/FSOFT v2/3 JSP Application Models.
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.
J2EE Chris Hundersmarck Maria Baron Jeff Webb.  Java 2 Platform, Micro Edition (J2ME)  Java 2 Platform, Standard Edition (J2SE)  Java 2 Platform, Enterprise.
Java Web 应用开发: J2EE 和 Tomcat 蔡 剑, Ph.D.. 本讲内容 信息系统实施的基本概念 面向对象的程序开发 Java 技术综述.
Modern Programming Language. Web Container & Web Applications Web applications are server side applications The most essential requirement.
Java Web 应用开发: J2EE 和 Tomcat 蔡 剑, Ph.D.. 本讲内容 Web 层技术 (II) Servlet 的新功能 JSP 技术.
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.
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 Custom Tag Library Chengyu Sun California State University, Los Angeles.
1 Introduction SAX. Objectives 2  Simple API for XML  Parsing an XML Document  Parsing Contents  Parsing Attributes  Processing Instructions  Skipped.
Java API for XML Processing
Struts 2 Development. Topics  Roles in Struts Development  Control Flow  Actions  Struts 2 Views and Target  Struts 2 Custom Tags  Validation 
CS3220 Web and Internet Programming Custom Tag Library
Pre-assessment Questions
Generate Dynamic Content On Cache Server
WaysInJavaToParseXML
XML document processing in Java using XPath and XSLT
WaysInJavaToParseXML
Presentation transcript:

Java Web 应用开发: J2EE 和 Tomcat 蔡 剑, Ph.D.

本讲内容 Web 层技术 (III) Custom Tags JSP and XML JSTL

Review: Use JavaBeans with JSP JSP Web Container Request Response BrowserServer Database JavaBeans JSP JSP handles the face. JavaBean handles the logic and complexity.

Custom JSP Tag 1.Simple Custom Tag: 2.Attribute Custom Tag: "/> Use tld file to config the tag attributes 3. Body Custom Tag: ……

Custom JSP Tag (Con’t) 4.Custom Tag can be used in Script:

Custom Tag Development 采用特定的 API 编写实现标签处理的程序 位置 /WEB-INF/classes or /WEB-INF/lib 建立一个 tag library descriptor ( TLD) 文件 用来描述 custom tag 位置 /WEB-INF

Tag Library Descriptor <!DOCTYPE taglib PUBLIC "-//Sun Microsystems, Inc.//DTD JSP Tag Library 1.2//EN" " - jsptaglibrary_1_2.dtd"> ics IcsampleTag Sample TLD in JWAD Book

Tag Library Descriptor (Con’t) wordcount jwadbook.taglib.WordCount empty inputname true false warnEmpty true boolean ……

A Simple Tag public class TimeTag implements Tag { … public int doStartTag() throws JspException { try { calendar = Calendar.getInstance(); pageContext.getOut().print( DateFormat.getDateInstance().format(calendar.getTime())+" "+ DateFormat.getTimeInstance().format(calendar.getTime()) ); } catch (IOException tage) { throw new JspException("TimeTag Error: "+ tage.getMessage()); } return SKIP_BODY; } public int doEndTag() throws JspException { return SKIP_PAGE; }

Simple Tag Result Current Time is:

A Attribute Tag public class WordCount extends TagSupport { public void setInputname(String _inputname) { this.inputname = _inputname; } public void setWarnEmpty(boolean _warnempty) { this.warnEmpty = _warnempty; } public int doEndTag() throws JspException { JspWriter out = pageContext.getOut(); inputword = pageContext.getRequest().getParameter(inputname); try{ if ((inputword==null)&&(warnEmpty==true)) { ……

A Attribute Tag else { StringTokenizer st = new StringTokenizer(inputword); int wordnumber = st.countTokens(); out.println(wordnumber); } } catch (IOException ioe) { System.out.println ("Error: " + ioe.getMessage()); } return EVAL_PAGE; }

Tld for the Example wordcount jwadbook.taglib.WordCount empty inputname true false warnEmpty true boolean

JSP with Custom Tag Enter A Brief Description Here Your have entered words in the above text area.

BodyTagSupport Sequences

BodyTagSupport Example public class ListTag extends BodyTagSupport { private int times; public void setTimes(int _times) { if(_times>0) { times = _times; } else { times = 1; } public int doStartTag() { if (times >= 1) { String timeString = String.valueOf(times); pageContext.getSession().setAttribute("ListTagTime", timeString); return(EVAL_BODY_INCLUDE); } else { return(SKIP_BODY); }

BodyTagSupport Example public void doInitBody() { } public int doAfterBody() { if (times-- > 1) { String timeString = String.valueOf(times); pageContext.getSession().setAttribute("Lis tTagTime", timeString); return(EVAL_BODY_AGAIN); } else { return(SKIP_BODY); }

RowTag inside ListTag public class RowTag extends TagSupport { public int doStartTag() { try { JspWriter out = pageContext.getOut(); int rowtime = 0; rowtime = Integer.parseInt((String)pageContext.getSession().getAt tribute("ListTagTime")); out.print(" Row Number: "+String.valueOf(rowtime)+" Created in RowTag "); } catch(IOException ioe) { System.err.println("RowTag error"); } return(EVAL_BODY_INCLUDE); }

BodyTagSupport Example Result

XML and Web Components Server Client DB RDMS EIS XMLDB XML EJB Servlet/Jsp XML DOM/SAX Query EJB HTML XSL XML WML XSL JDBC

XML Parsing using SAX JOB101 Prepare the design Requirements 10/1/ /10/2002 …… Parser startElement(“tasklist”, …) startElement(“task”, …) startElement(“taskid”, …) characters(char[],start,length) endElement(“taskid”, …) startElement(“name”, …) endElement(“tasklist”, …) …… XML Events

XML Parsing using DOM JOB101 Prepare the design Requirements 10/1/ /10/2002 …… Parser XML DOM Tree

A Example of Using DOM public static void main(String argv[]) { if (argv.length != 1) { System.err.println("Usage: java ProcessParser filename"); System.exit(1); } DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); try { DocumentBuilder builder = factory.newDocumentBuilder(); document = builder.parse( new File(argv[0]) ); makeFrame(); } catch (SAXException sxe) { // Error generated during parsing) Exception x = sxe; if (sxe.getException() != null) x = sxe.getException(); x.printStackTrace(); } catch (ParserConfigurationException pce) { pce.printStackTrace(); } catch (IOException ioe) { ioe.printStackTrace(); } } // main

JSP using XML Web Server XML JSP Custom Tag JavaBeans SAX/DOM

JSP using XSLT to Convert XML Client HTML XML WML Web Server XML JSP Custom Tag JavaBeans XSLT