Struts

Páginas: 5 (1162 palabras) Publicado: 29 de octubre de 2012
Using the JSP
Standard Tag Library
(JSTL) with Struts
Core Servlets & JSP book: www.coreservlets.com
More Servlets & JSP book: www.moreservlets.com
Servlet and JSP Training Courses: courses.coreservlets.com
2

Slides © Marty Hall, http://www.moreservlets.com, book © Sun Microsystems Press

For live Struts training, please see
JSP/servlet/Struts/JSF training courses athttp://courses.coreservlets.com/.
Taught by the author of Core Servlets and JSP, More
Servlets and JSP, and this tutorial. Available at public
venues, or customized versions can be held on-site at
your organization.
3

Slides © Marty Hall, http://www.moreservlets.com, book © Sun Microsystems Press

Agenda
• Obtaining JSTL documentation and code
• The JSTL Expression Language
• Looping Tags
– Loopinga certain number of times
– Looping over data structures

• Conditional Evaluation Tags
– Single choice
– Multiple choices

• Database Access Tags
• Other Tags
4

JSTL 1.0

www.moreservlets.com

Overview and
Installation

5

Slides © Marty Hall, http://www.moreservlets.com, book © Sun Microsystems Press

JSTL Overview
• JSTL is the recommended replacement for
the Strutslooping and logic tags
• JSTL is not part of the JSP 1.2 or 2.0 Specs
– It is a separate specification that requires a separate
download

– Available only in servers that support servlets 2.3 and
JSP 1.2 or later. Cannot be retrofitted into JSP 1.1.

• The JSTL expression language is now
part of JSP 2.0
• The JSTL Specification is available in PDF
–http://jcp.org/aboutJava/communityprocess/final/jsr052/
6

www.moreservlets.com

JSTL 1.0

Installing JSTL
• Some servers come with JSTL preinstalled
– E.g., Caucho Resin

• Official reference implementation
– http://jakarta.apache.org/builds/jakarta-taglibs/releases/standard/

• JSTL (like JSP) is a specification, not an
implementation
– Code is portable but not all versions are equal

• Speed, tools, anddevelopment environments
vary
• To install:

7

– Download zip file
– Unzip into directory of your choice (e.g., C:\jakarta-taglibs).
– Copy install_dir/standard-1.0.1/lib/jstl.jar and
install_dir/standard-1.0.1/lib/standard.jar to the WEB-INF/lib
www.moreservlets.com
directory of your Web application
JSTL 1.0

The JSTL Expression Language
• Accessed via ${expression}
• Similar toJavaScript and XPath
• Provides shorthand notation to access:
– Attributes of standard servlet objects
– Bean properties
– Map, List, and Array elements

• Is standard part of JSP 2.0
– In JSTL, EL can be used only in attributes of JSTL tags
– In JSP 2.0, the EL can be used anywhere
• web.xml element and page directive attribute let you disable the
EL for backward compatibility

• Covered inseparate lecture
8

JSTL 1.0

www.moreservlets.com

Iteration Tags

9

Slides © Marty Hall, http://www.moreservlets.com, book © Sun Microsystems Press

Looping Tags: Summary
• Looping with explicit numeric values

Blah, blah


• Looping over data structures
– Can loop down arrays, strings, collections, maps

Blah, blah


• Looping down delimited strings
– forTokens
10JSTL 1.0

www.moreservlets.com

Looping Tags: Motivation
• JSP without JSTL


(greater than 7)




22

JSTL 1.0

www.moreservlets.com

The "if" Tag (Results)

23

JSTL 1.0

www.moreservlets.com

The "choose" Tag






(small)


(medium)


(large)




24

JSTL 1.0

www.moreservlets.com

The "choose" Tag (Results)

25

JSTL 1.0www.moreservlets.com

Database Access
Tags

Slides © Marty Hall, http://www.moreservlets.com, book © Sun Microsystems Press

26

Database Access Tags

– Specifies data source (can also be set by config settings)


– Queries database and stores ResultSet in variable
– Warning: this usage violates rule of keeping business
logic out of presentation layer. Instead, do database
access in...
Leer documento completo

Regístrate para leer el documento completo.

Estos documentos también te pueden resultar útiles

  • Struts
  • Struts
  • Struts
  • Struts
  • Struts 2
  • Struts Java
  • Struts Introduction
  • Struts (resumen)

Conviértase en miembro formal de Buenas Tareas

INSCRÍBETE - ES GRATIS