JSTL Lec - 43. Umair©2006, All rights reserved JSTL (ni) Acronym of  JavaServer Pages Standard Tag Library JSTL (like JSP) is a specification, not an.

Slides:



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

CF and JSP/Servlets Developed originally by Robi Sen For the CF UnderGround II Seminar, Apr 2001 Edited and enhanced by Charlie Arehart (Robi had an emergency.
Java Script Session1 INTRODUCTION.
Apache Struts Technology
Expression Language Lec Umair Javed©2006 Generating Dynamic Contents Technologies available  Servlets  JSP  JavaBeans  Custom Tags  Expression.
 Copyright Wipro Technologies JSP Ver 1.0 Page 1 Talent Transformation Java Server Pages.
Chapter 51 Scripting With JSP Elements JavaServer Pages By Xue Bai.
Using JavaServer Pages Harry R. Erwin, PhD CIT304/CSE301.
JSP: JavaServer Pages Juan Cruz Kevin Hessels Ian Moon.
WEB1P servintro1 Introduction to servlets and JSP Dr Jim Briggs.
28/1/2001 Seminar in Databases in the Internet Environment Introduction to J ava S erver P ages technology by Naomi Chen.
Fast Track to ColdFusion 9. Getting Started with ColdFusion Understanding Dynamic Web Pages ColdFusion Benchmark Introducing the ColdFusion Language Introducing.
DT211/3 Internet Application Development
Layers & Tiers Umair Javed Lec - 41.
DT228/3 Web Development JSP: Directives and Scripting elements.
DT228/3 Web Development Databases. Database Almost all web application on the net access a database e.g. shopping sites, message boards, search engines.
DT211/3 Internet Application Development Databases.
Apache Struts Technology A MVC Framework for Java Web Applications.
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.
Introduction to Java web programming Dr Jim Briggs JWP intro1.
Eclipse is an open source IDE (Integrated Development Environment) for developing applications in Java, C/C++, HTML, Cobol, Perl, etc. The official Eclipse.
UNIT-V The MVC architecture and Struts Framework.
 2004 Prentice Hall, Inc. All rights reserved. Chapter 37 - JavaServer Pages (JSP): Bonus for Java Developers Outline 37.1 Introduction 37.2 JavaServer.
Overview of JSP Technology. The need of JSP With servlets, it is easy to – Read form data – Read HTTP request headers – Set HTTP status codes and response.
1 CIS336 Website design, implementation and management (also Semester 2 of CIS219, CIS221 and IT226) Lecture 9 JavaServer Pages (JSP) (Based on Møller.
Netbeans – jsp.zip Introduction to JSP Netbeans – jsp.zip.
M. Taimoor Khan * Java Server Pages (JSP) is a server-side programming technology that enables the creation of dynamic,
JSP Standard Tag Library
CSCI 6962: Server-side Design and Programming Course Introduction and Overview.
CSC 2720 Building Web Applications Using Java Beans, Custom Tags and Tag Libraries in JSP pages.
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
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.
Introduction to JavaServer Pages (JSP) Slides from Dr. Mark Llewellyn.
Java Server Pages Lecture July Java Server Pages Java Server Pages (JSPs) provide a way to separate the generation of dynamic content (java)
Organization of the platform Your application Java language Java Servlet API JavaServer Pages (JSP) JSTL Your web pages.
® IBM Software Group © 2007 IBM Corporation JSP Expression Language
JSTL JSP Standard Tag Library 12-Oct-15. W HAT IS JSTL? JSTL (JSP Standard Tag Libraries) is a collection of JSP custom tags developed by Java Community.
Lecturer: Prof. Piero Fraternali, Teaching Assistant: Alessandro Bozzon, Advanced Web Technologies: Struts–
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.
JSTL, XML and XSLT An introduction to JSP Standard Tag Library and XML/XSLT transformation for Web layout.
JSTL: The JavaServer Pages Standard Tag Library Mark A. Kolb Security Broadband, Austin, TX
Copyright © 2002 ProsoftTraining. All rights reserved. JavaServer Pages.
JSTL The JavaServer Pages Standard Tag Library (JSTL) is a collection of useful JSP tags which encapsulates core functionality common to many JSP applications.
DT228/3 Web Development Databases. Querying a database: Partial info Search engines, on-line catalogues often need to allow user to search a database.
An Introduction to JavaServer™ Pages Prepared by Nicole Swan.
JSP BASICS AND ARCHITECTURE. Goals of JSP Simplify Creation of dynamic pages. Separate Dynamic and Static content.
JAVA BEANS JSP - Standard Tag Library (JSTL) JAVA Enterprise Edition.
© 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.
8 Chapter Eight Server-side Scripts. 8 Chapter Objectives Create dynamic Web pages that retrieve and display database data using Active Server Pages Process.
Preface IIntroduction Objectives I-2 Course Overview I-3 1Oracle Application Development Framework Objectives 1-2 J2EE Platform 1-3 Benefits of the J2EE.
Chapter 3 JSP Overview. The Problem with Servlets processing the request and generating the response are both handled by a single servlet class Java programming.
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 Programming: Advanced Topics 1 Building Web Applications Chapter 13.
10 Copyright © 2004, Oracle. All rights reserved. Building ADF View Components.
APACHE STRUTS ASHISH SINGH TOMAR ast2124. OUTLINE Introduction The Model-View-Controller Design Pattern Struts’ implementation of the MVC Pattern Additional.
Dr. Abdullah Almutairi Spring PHP is a server scripting language, and a powerful tool for making dynamic and interactive Web pages. PHP is a widely-used,
Apache Struts Technology A MVC Framework for Java Web Applications.
Lecture Transforming Data: Using Apache Xalan to apply XSLT transformations Marc Dumontier Blueprint Initiative Samuel Lunenfeld Research Institute.
Web browser Web server HTML request Scripted pagedatabase The following components will be used: Apache Jakarta Tomcat servlet engine Derby JavaServer.
JSP: Actions elements and JSTL
JSP (Java Server Page) JSP is server side technology which is used to create dynamic web pages just like Servlet technology. This is mainly used for implementing.
CS3220 Web and Internet Programming JSP Standard Tag Library (JSTL)
Knowledge Byte In this section, you will learn about:
JSP Standard Tag Library
Presentation transcript:

JSTL Lec - 43

Umair©2006, All rights reserved JSTL (ni) Acronym of  JavaServer Pages Standard Tag Library JSTL (like JSP) is a specification, not an implementation Official reference implementation  Development theme  No Scriptlets

Umair©2006, All rights reserved JSTL Overview (ni) JSTL tags are valid XML JSTL contains action (tags) for common tasks  Iteration  Session Tracking  Redirect  XML  SQL etc. Remember – the development theme is “no scriptlets”

Umair©2006, All rights reserved Organization of the platform Your application Java language Java Servlet API JavaServer Pages (JSP) JSTL Your web pages EL

Umair©2006, All rights reserved Why JSTL? (ni) JSTL tags provide a standard implementation for typical application functionality  Reusability  Avoid reinventing the wheel Another mechanism for avoiding the use of JSP scripting elements  EL considerably simple than Java

Umair©2006, All rights reserved JSTL & EL (ni) JSTL includes support for EL  To replace the JSP expressions EL is also standard part of JSP 2.0 EL can only be used in attributes of JSTL tags prior to JSP 2.0  With JSP 2.0 and onwards, it can be used anywhere in the document

Umair©2006, All rights reserved JSTL Tag libraries Composed of 4 standard tag libraries  Core Conditions, Control flow & variables access etc.  Internationalization / format Locale messages Text, numbers & date formation  XML XML parsing / processing  SQL Tags for accessing an SQL database

Umair©2006, All rights reserved Twin Tag Libraries JSTL comes in two flavors  Request Time (RT) version Dynamic attribute values are specified using JSP expression (i.e. )  Expression Language (EL) version Dynamic attribute values are specified using JSTL expression language (i.e. ${ expression } ) Why ?

Umair©2006, All rights reserved JSTL Tag libraries (cont.) LibraryURIPrefix Core c SQL sql Internationalization / Format fmt XMLhttp://java.sun.com/jsp/jstl/xml x EL based

Umair©2006, All rights reserved JSTL Tag libraries (cont.) LibraryURIPrefix Core c_rt SQL sql_rt Internationalization / Format fmt_rt XMLhttp://java.sun.com/jsp/jstl/xml_rt x_rt RT based

Umair©2006, All rights reserved Using JSTL Use taglib directive, as we used for custom tag library For example  To use EL based core tag library  To use RT based core tag library

Umair©2006, All rights reserved Working with Core Actions (tags)

Umair©2006, All rights reserved Core Tag Library Support actions  Manipulation of scoped variables  Output  Conditional logic  loops  URL manipulation  and Handling errors.

Umair©2006, All rights reserved Core Tag Library c:set [1]  Provides a tag based mechanism for creating and setting scope based variables  Syntax:  var  Specifies the name of the scoped variables  scope  page | request | session | application  Optional and defaults to page  value  Specifies the value to be bound to the variable  If evaluates to NULL, attribute/var will be removed if exist.

Umair©2006, All rights reserved Core Tag Library c:set [2]  Examples

Umair©2006, All rights reserved Core Tag Library Using c:set forJavaBeans & Map [1]  Syntax: <c:set target=“beanOrMap” property =“propertyOrKey” value = “value” /> Target must not be NULL If target is a bean, sets the value of the property, equivalent to If target is a Map, sets the value of the key

Umair©2006, All rights reserved Core Tag Library Using c:set forJavaBeans [2]  Example <jsp:useBean id=“person” class=“vu.PersonInfo” scope=“request” />

Umair©2006, All rights reserved Core Tag Library c:out [1]  Equivalent to JSP expression i.e.  Syntax:  value  Evaluates the value attribute and outputs the result as string  default  Prints it if the value attribute evaluates to null or empty string  Optional

Umair©2006, All rights reserved Core Tag Library c:out [2]  Examples: Is equivalent to: <% String no = request.getParameter(“num”); if (no == null ) System.out.println(no); %>

Umair©2006, All rights reserved Core Tag Library c:remove  Used to delete a scoped variable  Syntax:  Examples:

Umair©2006, All rights reserved Core Tag Library c:forEach [1]  Used for iteration purpose  Supports two different styles of iteration Iteration over an integer range Iteration over a collection

Umair©2006, All rights reserved Core Tag Library c:forEach [2] (ni)  Iteration over an Integer Range [1] Like java language’s for statement  Syntax: <c:forEach var=“name” begin=“expression” end=“expression” step=“expression” /> Body Content If omitted, by default 1

Umair©2006, All rights reserved Core Tag Library c:forEach [3] (ni)  Iteration over an Integer Range [2] Example: To generate squares corresponding to range of integer values

Umair©2006, All rights reserved Core Tag Library c:forEach [4]  Iteration over a Collection [1] Can loop down on arrays, strings, list & map etc. Syntax: Body Content ArrayList HashMap Arrays etc.

Umair©2006, All rights reserved Core Tag Library c:forEach [5]  Iteration over a Collection [2] Example: To iterate over a String array <% for(int i=0; i<messages.length; i++) { String message = messages[i]; %> <% } // end for %> JSP without JSTL JSP after JSTL

Umair©2006, All rights reserved Core Tag Library c:forEach [6]  Iteration over a Collection [3] Example: To iterate over a persons ArrayList, contains PersonInfo objects <% ArrayList persons = (ArrayList)request.getAttribute(“pList”) for(int i=0; i<persons.size(); i++) { PersonInfo p == (PersonInfo)persons.get(i); String name = p.getName(); %> <% } // end for %> JSP without JSTL Type cast needed JSP after JSTL Automatic Type Conversion to appropriate type

Exampole code Addressbook(MVC) using core tags netBeans project – jstl_ex2

Umair©2006, All rights reserved Core Tag Library (ni) c:if  Used to conditionally process the body content  Syntax: Body content  Example: a equals b

Umair©2006, All rights reserved Core Tag Library (ni) c:choose [1]  Enables mutually exclusive conditionals  Syntax: Body content ……………. Body content -- Must appear at-least once -- Only one is processed whose test evaluates to true -- Can appear at-most once -- Only execute if all tests evaluate to false

Umair©2006, All rights reserved Core Tag Library (ni) c:choose [2]  Example: a equal b a equal c Don’t know what ‘a’ equal

Umair©2006, All rights reserved Working with SQL Actions (tags)

Umair©2006, All rights reserved SQL Tag Library Support actions  To interact with relational databases  Issuing queries & updates  transactions etc.

Umair©2006, All rights reserved SQL Tag Library sql:setDataSource [1]  Used for specifying data source  Syntax: <sql:setDataSource driver=“driver_name” url = “url” user = “user” password =“pwd” />

Umair©2006, All rights reserved SQL Tag Library sql:setDataSource [2]  Example: To connect with Microsoft Access database <sql:setDataSource driver = “sun.jdbc.odbc.JdbcOdbcDriver” url = “jdbc:odbc:PersonDSN” user = “” password = “” />

Umair©2006, All rights reserved SQL Tag Library sql:query  Used to execute queries  Syntax: <sql:query sql = “expression” var = “name” scope = “scope” /> -- Results of query stored -- Optional attribute to specify where to store var

Umair©2006, All rights reserved SQL Tag Library sql:query [2]  Example: executing a simple select query & processing results <sql:query sql = “SELECT * FROM PersonInfo” var = “res” /> Contains results of query

Exampole code Addressbook(MVC) using core & sql tags netBeans project – jstl_ex

Umair©2006, All rights reserved SQL Tag Library (ni) Problems  Heinous violation of MVC design pattern DB code (i.e. raw SQL) doesn’t belong in the presentation layer

Insert slide that contains only jsp pages – addressbook using only jsp pages

Umair©2006, All rights reserved Bringing it all together (lec 45 slide) Java provides these mechanisms for internet programming  Applets  Servlets  Java Server pages Scripting elements JSP Standard Tag library JSTL Expression language Java Beans (Enterprise Java Beans) Ultimately leads to easier, faster, and more powerful web application development?