CSC 2720 Building Web Applications JavaServer Pages (JSP) JSP Directives and Action Elements.

Slides:



Advertisements
Similar presentations
8 Copyright © 2005, Oracle. All rights reserved. Creating the Web Tier: JavaServer Pages.
Advertisements

Java Server Pages Jeffrey Jongko. Introduction Java Server Pages (JSP) technology was created by Sun Microsystems and is built on top of Sun’s Java Servlet.
JSP1 Java Server Pages (JSP) Introducing JavaServer Pages TM (JSP TM ) JSP scripting elements.
 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.
The JSP Directives Vijayan Sugumaran School of Business Administration Oakland University Parts of this lecture provided by Coreservlets.com.
J2EE Servlets and JSP Advanced topics Presented by Bartosz Sakowicz.
DT211/3 Internet Application Development
DT228/3 Web Development JSP: Directives and Scripting elements.
Including Files & Applets in JSP Documents Parts of this presentation provided by: Vijayan Sugumaran Decision and Information Sciences.
1 CS6320 – JSP L. Grewe 2 Java Server Pages Servlets require you to write out entire page delivered with print statements Servlets require you to write.
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.
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.
Java Server Pages CS-422. What are JSPs A logical evolution of java servlets –most servlets dynamically create HTML and integrate it with some computational.
M. Taimoor Khan * Java Server Pages (JSP) is a server-side programming technology that enables the creation of dynamic,
1 Chapter 1: Overview of Servlets and JavaSerevr Pages.
CSC 2720 Building Web Applications Using Java Beans, Custom Tags and Tag Libraries in JSP pages.
Slides © Marty Hall, book © Sun Microsystems Press 1 Including Files & Applets in JSP Documents Core Servlets & JSP book:
J2EE training: 1 Course Material Usage Rules PowerPoint slides for use only in full-semester, for-credit courses at degree-granting.
1 JSP – Java Server Pages Representation and Management of Data on the Internet.
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.
Introduction to Java Server Pages (JSPs) Robert Thornton.
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)
JSP Most of the web developers deploying web applications using servlets mixes the presentation logic and business logic. Separation of business logic.
Mark Dixon 1 12 – Java Beans. Mark Dixon 2 Session Aims & Objectives Aims –To cover the use of Java Beans Objectives, by end of this week’s sessions,
JAVA SERVER PAGES. 2 SERVLETS The purpose of a servlet is to create a Web page in response to a client request Servlets are written in Java, with a little.
JAVA SERVER PAGES CREATING DYNAMIC WEB PAGES USING JAVA James Faeldon CS 119 Enterprise Systems Programming.
Slides © Marty Hall, book © Sun Microsystems Press 1 JSP Scripting Elements Core Servlets & JSP book:
J2EE training: 1 Course Material Usage Rules PowerPoint slides for use only in full-semester, for-credit courses at degree-granting.
Introduction to JavaServer Pages. 2 JSP and Servlet Limitations of servlet  It’s inaccessible to non-programmers JSP is a complement to servlet  focuses.
JSP Fundamentals Elements of a JSP Using Beans with JSP Integrating Servlets and JSP.
CSC 2720 Building Web Applications JavaServer Pages (JSP) The Basics.
Java server pages. A JSP file basically contains HTML, but with embedded JSP tags with snippets of Java code inside them. A JSP file basically contains.
Copyright © 2002 ProsoftTraining. All rights reserved. JavaServer Pages.
Java Server Pages (JSP)
Java Server Pages An introduction to JSP. Containers and Components Several clients – one system.
3/6/00jsp00 1 Java Server Pages Nancy McCracken Northeast Parallel Architectures Center at Syracuse University.
JSP. Types of JSP Scripting Elements Expressions of the form, which are evaluated and inserted into the servlet's output. Scriptlets of the form, which.
Web Technologies Java Beans & JSP By Praveen Kumar G.
JSP BASICS AND ARCHITECTURE. Goals of JSP Simplify Creation of dynamic pages. Separate Dynamic and Static content.
© 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.
JSP – Java Server Page DBI – Representation and Management of Data on the Internet.
Liang, Introduction to Java Programming, Ninth Edition, (c) 2013 Pearson Education, Inc. All rights reserved. 1 Chapter 43 JavaServer Page.
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.
1 Chapter 27 JavaServer Page. 2 Objectives F To know what is a JSP page is processed (§27.2). F To comprehend how a JSP page is processed (§27.3). F To.
Chapter 6 Chapter 6 Server Side Programming (JSP) Part 1 1 (IS 203) WebProgramming (IS 203) Web Programming.
JAVA SERVER PAGES -by Rubeena Memon Deepti Jain Jaya Thakar Jisha Vettuventra.
DT228/3 Web Development JSP: Actions elements and JSTL.
Chapter 14 Using JavaBeans Components in JSP Documents.
JSP Directive and Objects. JSP Directives As discussed before There are 3 types of elements in JSP Directive Elements Scripting Elements Standard Action.
JSP Java Server Pages. Hello, !
JSP Action Elements Lec - 37.
Developing JavaServer Pages
Java Server Pages.
Java Server Pages By: Tejashri Udavant..
Scripted Page Web App Development (Java Server Pages)
Including Files and Applets in JSP Pages
Pre-assessment Questions
Knowledge Byte In this section, you will learn about:
Invoking Java Code from JSP
Java Server Pages B.Ramamurthy.
JSP Directives 1-Jan-19.
JSP implicit objects & directive elements
Introduction to JSP Dept. of B.Voc Software Development and System Administration St. Joseph’s College(Autonomous) Trichy-02 By Dr. J. Ronald Martin Introduction.
Web Technologies Java Beans & JSP
Presentation transcript:

CSC 2720 Building Web Applications JavaServer Pages (JSP) JSP Directives and Action Elements

JSP Directives  page directives – defines attributes that apply to an entire JSP page  include directives – includes a resource of text or code when the JSP page is translated  taglib directives – defines a tag library and prefix for the custom tags used in the JSP page  Syntax:   directive attribute 1 ="value 1 " attribute 2 ="value 2 "... %> where directive can be page, include, or taglib

page Directives  Defines attributes that apply to an entire JSP page. Which classes are imported  For examples,  To specify a different superclass for the current JSP page  To specify the MIME type of the generated content  To indicate if the JSP page is thread safe or not  To turn on/off automatic session participation  To change the size and behavior of the output buffer  To indicate which page is to be used to handle unexpected errors/exceptions

page Directives – import  Syntax   Note: To import all classes from a package, use package.*  Purpose  Generate import statements at for the resulting servlet class  Note:  Class files should be placed under the folder …/Web_App_Name/WEB-INF/classes and in the appropriate sub-folders that match the package name. .jar library files should be placed under the folder …/Web_App_Name/WEB-INF/lib

page Directives – contentType  Syntax   Purpose  Specify the MIME type of the content generated by the JSP page  Default value is "text/html;charset=ISO "  e.g.: HTML content encoded in simplified Chinese characters   References  Wiki: MIME:  MIME reference:  Character set reference:

First Last Address Marty Hall Larry Brown Bill Gates Larry Ellison <%-- Note: The values are separated by tabs and not by spaces --%> Generating Excel Spreadsheets

Other Attributes of the page Directive  session  Lets you turn on/off session participation  Default value is "true"  e.g.:  extends  Changes parent class of the resulting servlet  isThreadSafe  Lets you specify whether the JSP page is thread safe  Default value is "true"  Setting this attribute to "false" makes the resulting servlet a single- threaded servlet  e.g.:

Other Attributes of the page Directive  language  Let you specify the scripting language  Default value is "java"  info  Allows you to insert a string that later can be retrieved using the getServletInfo() method.  e.g.:  buffer  Changes the minimum size of buffer used by JspWriter  The unit of the size is in kilobyte  e.g.: means don't buffer the output  e.g.: means set buffer size to 12kbytes  autoflush  Requires the developer to explicitly flush buffer

Other Attributes of the page Directive  errorPage  Designates a page to handle unplanned errors (i.e., when an exception is uncaught in the JSP page)  e.g.:  isErrorPage  Indicates if the current page is a page designated for handling error  Default value is "false"  If "true", the "exception" implicit object is made available to this page.  You can find out from the "exception" object which JSP page is throwing an exception and what kind of exception it is.  Note: We can also configure error pages in the web.xml (web application deployment file).

A Note On Directive Elements  Except for " import ", other attributes cannot repeat.  The following is illegal  The following is illegal page buffer="16384" session="false" buffer="8192" %>  The following is legal

The include Directive  Static include – to include the contents of other files in the current JSP page at translation time.  Syntax: // Content A // Content B // Content X // Content A // Content X // Content B Translated into Servlet codes original.jsp x.html Notes: Servers may not detect changes made to the included files. Thus, you need to update the "last modified date" of the JSP files whenever the included files change.

The include Directive  Purposes  To reuse JSP content in multiple pages  e.g.: Menus, headers, footers, etc.  When to use  If the included file contains static text  If the included file is rarely changed  To include files (including JSP fragment files) that are placed under the /WEB-INF folder.  Shortcoming  Lack of locality (The main file and all the included files share the same scope  difficult to debug)  Not suitable for files that’s are too big. (A Java method cannot exceeds 64kbytes in size.)

Standard Action Elements  Special Tags that can be embedded in a JSP page  At compile time, these tags are also converted into corresponding Java codes.  7 standard JSP action elements:  jsp:include, jsp:forward, jsp:param  More commonly used ones  jsp:useBean, jsp:setProperty, jsp:getProperty  For used with JSP Bean (Will discussed later)  jsp:plugin  For generating or tags for Java applet.

jsp:include Action  Dynamic include – To incorporate static or dynamic resources into the current page at request time.  Similar to using a RequestDispatcher object to include a resource  Can pass data to the included resources  Syntax or …

jsp:include Action // Content A // Content B // Content X // Java codes to produce content A pageContext.include("x.html"); // Java codes to produce content B Translated into servlet codes original.jsp x.html Java byte codes Compiled into Java byte codes Executed by web container Included into the output stream at rune time. If the included resource is a JSP file, the output produced by the JSP file is included in the output stream of original.jsp.

jsp:include Action  Advantages over the include directive  Easier to maintain  Changes made to the included files automatically reflected in the files that include them.  Easier to debug (Strong locality)  Shortcoming  Slower  Cannot include files placed in /WEB-INF folder  When to use  If the file is subject to modification very often  If the size of the file is huge

Include Example – Menu Menu Item 1 Menu Item 2 Menu Item 3 JSP Menu Demo Contents goes here... menu.html (note: With include directive, you can give any file extension to this file.) In this example, using produces same output

Reusable JSP Content: ContactSection.jsp <%-- The following become fields in each servlet object that results from a JSP page that includes this file. --%> <%! private int accessCount = 0; private Date accessDate = new Date(); private String accessHost = " No previous access "; %> © 2000 my-company.com. This page has been accessed times since server reboot. It was last accessed from at.

… Some Random Page Information about our products and services. Blah, blah, blah. Yadda, yadda, yadda. Using the JSP Content

jsp:forward Action  Used to instruct a web server to stop processing the current page and start another one.  Similar to using a RequestDispatcher object to forward a request  Syntax or …

Note: For both jsp:include and jsp:forward  The parameters passed to the included/forwarded resources can be obtained as request.getParameter("paramName")  If the value of page attribute begins with '/', then the path is evaluated relative to the application root folder. Otherwise the path is evaluated relative to the current folder.

 References  Wikipedia: JavaServer Pages  Free Tutorial (Java, JSP, Java Servlets)  Sample JSP codes