CS3220 Web and Internet Programming JSP Standard Tag Library (JSTL)

Slides:



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

Apache Struts Technology
CS320 Web and Internet Programming Generating HTTP Responses
DT211/3 Internet Application Development
CS320 Web and Internet Programming JSP Standard Tag Library (JSTL) Chengyu Sun California State University, Los Angeles.
Introduction to Java web programming Dr Jim Briggs JWP intro1.
Chapter 10 Servlets and Java Server Pages. A servlet is a Java class designed to be run in the context of a special servlet container An instance of the.
Struts. Agenda Preface Struts and its components An example The architecture required for Struts Applications.
Form Handling, Validation and Functions. Form Handling Forms are a graphical user interfaces (GUIs) that enables the interaction between users and servers.
JSP Standard Tag Library
CSC 2720 Building Web Applications Using Java Beans, Custom Tags and Tag Libraries in JSP pages.
® IBM Software Group © 2007 IBM Corporation JSP Custom Tags
CSCI 6962: Server-side Design and Programming Java Server Faces Components and Tags.
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.
Website Development with PHP and MySQL Saving Data.
JSTL Lec Umair©2006, All rights reserved JSTL (ni) Acronym of  JavaServer Pages Standard Tag Library JSTL (like JSP) is a specification, not an.
Fall 2007cs4201 Advanced Java Programming Umar Kalim Dept. of Communication Systems Engineering
Chapter 7 Using Custom Tag Libraries and the JSP Standard Tag Library.
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.
CS320 Web and Internet Programming Custom Tag Library Chengyu Sun California State University, Los Angeles.
OOSSE Week 8 JSP models Format of lecture: Assignment context JSP models JSPs calling other JSPs i.e. breaking up work Parameter passing JSPs with Add.
1 Web Programming with Servlets & JSP ASSIGNMENT GUIDELINE.
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.
©SoftMooreSlide 1 Introduction to HTML: Forms ©SoftMooreSlide 2 Forms Forms provide a simple mechanism for collecting user data and submitting it to.
Adapted from  2012 Prentice Hall, Inc. All rights reserved. 5 th ed: Chapter 2 and th ed: 4.11 SY306 Web and Databases for Cyber Operations.
JSP Standard Tag Library (JSTL) Internet Computing KUT Youn-Hee Han.
Java Programming: Advanced Topics 1 Building Web Applications Chapter 13.
10 Copyright © 2004, Oracle. All rights reserved. Building ADF View 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.
Lecture Transforming Data: Using Apache Xalan to apply XSLT transformations Marc Dumontier Blueprint Initiative Samuel Lunenfeld Research Institute.
CS520 Web Programming Spring – Web MVC Chengyu Sun California State University, Los Angeles.
Struts 2 Development. Topics  Roles in Struts Development  Control Flow  Actions  Struts 2 Views and Target  Struts 2 Custom Tags  Validation 
Web browser Web server HTML request Scripted pagedatabase The following components will be used: Apache Jakarta Tomcat servlet engine Derby JavaServer.
Introduction to Servlets
CS3220 Web and Internet Programming Custom Tag Library
Computing with C# and the .NET Framework
CS520 Web Programming Servlet and JSP Review
CS320 Web and Internet Programming Database Access with JSTL SQL
Chengyu Sun California State University, Los Angeles
JSP: Actions elements and JSTL
CS320 Web and Internet Programming Generating HTTP Responses
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.
CS520 Web Programming Servlet and JSP Review
CS520 Web Programming Servlet and JSP Review
CS320 Web and Internet Programming JSP Standard Tag Library (JSTL)
Knowledge Byte In this section, you will learn about:
JSP Standard Tag Library
CS5220 Advanced Topics in Web Programming Spring – Web MVC
CS320 Web and Internet Programming Cookies and Session Tracking
CS320 Web and Internet Programming MVC Architecture
CS3220 Web and Internet Programming Cookies and Session Tracking
JSP Directives 1-Jan-19.
Chengyu Sun California State University, Los Angeles
CS5220 Advanced Topics in Web Programming Spring – Web MVC
Creating Forms on a Web Page
CS3220 Web and Internet Programming JavaScript Basics
CS3220 Web and Internet Programming Introduction to Java Servlets
CS3220 Web and Internet Programming Handling HTTP Requests
Chengyu Sun California State University, Los Angeles
CS3220 Web and Internet Programming Cookies and Session Tracking
Chengyu Sun California State University, Los Angeles
CS4961 Software Design Laboratory Understand Aquila Backend
CS3220 Web and Internet Programming JavaScript Basics
Struts BY: Tejashri Udavant..
Presentation transcript:

CS3220 Web and Internet Programming JSP Standard Tag Library (JSTL) Chengyu Sun California State University, Los Angeles

Custom Tags in ASP.NET <p>Enter a number from 1 to 100: <asp:TextBox id="tbox1" runat="server" /> <asp:Button Text="Submit" runat="server" /> </p>

Custom Tags in ColdFusion <cfform action = “cftextinput.cfm” method=“post”> <cftextinput name = “myInput” message = “This field must not be blank” required = “Yes” /> <input type = “Submit” value =“submit” /> </cfform>

Simple JSTL Example <%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %> <html><head><title>JSTL Hello</title></head> <body> <c:out value="Hello World in JSTL." /> </body> </html>

taglib Directive URI Prefix A unique identifier for the tag library NOT a URL Prefix A short name for the tag library Could be an arbitrary name

JSP Standard Tag Library (JSTL) URI Prefix Core http://java.sun.com/jsp/jstl/core c XML Processing http://java.sun.com/jsp/jstl/xml x I18N Formatting http://java.sun.com/jsp/jstl/fmt fmt Database Access http://java.sun.com/jsp/jstl/sql sql Functions http://java.sun.com/jsp/jstl/functions fn http://download.oracle.com/docs/cd/E17802_01/products/products/jsp/jstl/1.1/docs/tlddocs/index.html

Important JSTL Tags and Functions Flow control <c:if> <c:choose> <c:when> <c:otherwise> <c:forEach> URL <c:url> Output <c:out> Formatting <fmt:formatDate> <fmt:formatNumber> Functions fn:length()

Branch Tags … <c:if test=“${a.weekdays[0] == ‘mon’}”>Monday</c:if> The type of the test attribute is boolean, which requires EL; “a.weekdays[0]==‘mon’” would be just a String.

… Branch Tags <c:choose> <c:when test="${a.weekdays[3] == 'tue'}"> Tuesday </c:when> <c:when test="${a.weekdays[3] == 'wed'}"> Wednesday</c:when> <c:when test="${a.weekdays[3] == 'thr'}"> Thursday <c:otherwise>Friday</c:otherwise> </c:choose>

Loop Tag <c:forEach> … The type of the items attribute is Collection (i.e. list, set, etc.) <ul> <c:forEach items="${a.numbers}" var="number"> <li>${number}</li> </c:forEach> </ul> The type of the var attribute is simply String

… Loop Tag <c:forEach> … It’s similar to the “enhanced for loop” in Java var items for( Double number : a.getNumbers() ) System.out.println( number );

… Loop Tag <c:forEach> Use varStatus variable to get the information of each iteration http://docs.oracle.com/javaee/5/jstl/1.1/docs/api/javax/servlet/jsp/jstl/core/LoopTagStatus.html <ul> <c:forEach items="${a.numbers}" var="number" varStatus="status"> <li>${status.index}: ${number}</li> </c:forEach> </ul>

URL Tag <c:url> <a href="<c:url value='/JSTLTest' />">A</a> <c:url value=“/JSTLTest” /> For <c:url>, a URL starts with “/” is relative to the application root instead of the server root.

Output Tag <c:out> <c:out value=“abc” /> <c:out value=“${a.id}” /> <c:out value=“a<b>c” /> “abc” ${a.id} ?? You want to use <c:out> if escapeXml=true value is a Java.io.Reader object

Convert Special Characters When escapeXml=true < > & & ‘ ' “ "

Format Date and Time with <fmt:formatDate> <fmt:formatDate value=“${a.date}” type=“date” /> <fmt:formatDate value=“${a.date}” type=“time” /> <fmt:formatDate value=“${a.date}” type=“both” /> <fmt:formatDate value=“${a.date}” pattern=“yyyy-M-d h:m:s a” /> See http://download.oracle.com/javase/7/docs/api/java/text/SimpleDateFormat.html for the date formatting patterns.

Format Numbers with <fmt:formatNumber> <fmt:formatNumber value=“${number}” type=“number” /> <fmt:formatNumber value=“${number}” type=“currency” /> <fmt:formatNumber value=“${number}” type=“percent” /> <fmt:formatNumber value=“${number}” pattern=“0.##” /> See https://docs.oracle.com/javase/7/docs/api/java/text/DecimalFormat.html for the number formatting patterns.

Use JSTL function fn:length() ${ fn:length(“cs3220”) } Length of a String Size of a collection ${ fn:length(a.numbers) } Can only be used in EL More at http://docs.oracle.com/cd/E17802_01/products/products/jsp/jstl/1.1/docs/tlddocs/index.html

Example: GuestBook (MVC) Convert GuestBook (Servlet) to MVC with EL and JSTL

Custom Tags Are “Server Tags” Browser Application Server HTTP request HTML HTTP response Client Servlet <c:if> … Users only see regular HTML tags. Server