Including Files & Applets in JSP Documents Parts of this presentation provided by: www.coreservlets.com Vijayan Sugumaran Decision and Information Sciences.

Slides:



Advertisements
Similar presentations
Java Script Session1 INTRODUCTION.
Advertisements

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.
got ? Research Project – April 1998 Hang Xia, Mark Wang, Richard S. Chang Updated: R Norman, August 1999.
1 Frameworks. 2 Framework Set of cooperating classes/interfaces –Structure essential mechanisms of a problem domain –Programmer can extend framework classes,
Object-Oriented Enterprise Application Development Tomcat 3.2 Configuration Last Updated: 03/30/2001.
DT211/3 Internet Application Development
18-Jun-15 JSP Java Server Pages Reference: Tutorial/Servlet-Tutorial-JSP.html.
DT228/3 Web Development JSP: Directives and Scripting elements.
Python and Web Programming
Java Server Pages Russell Beale. What are Java Server Pages? Separates content from presentation Good to use when lots of HTML to be presented to user,
1 Java Server Pages Can web pages be created specially for each user? What part does Java play?
The tag The complete syntax of the tag is as follows( code, width and height are required and others optional)
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.
Web Programming Material From Greenlaw/Hepp, In-line/On-line: Fundamentals of the Internet and the World Wide Web 1 Introduction The JavaScript Programming.
Javascript and the Web Whys and Hows of Javascript.
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,
4.1 JavaScript Introduction
FALL 2005CSI 4118 – UNIVERSITY OF OTTAWA1 Part 4 Web technologies: HTTP, CGI, PHP,Java applets)
1 APPENDIX D OVERVIEW OF JSP, JSTL, and EL TAGS. 2 OVERVIEW OF JSP, JSTL, and EL TAGS This appendix describes how to create and modify JSP pages in JD.
CS346 - Javascript 1, 21 Module 1 Introduction to JavaScript CS346.
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.
Chapter 17 - Deploying Java Applications on the Web1 Chapter 17 Deploying Java Applications on the Web.
CNIT 133 Interactive Web Pags – JavaScript and AJAX JavaScript Environment.
Introduction to Java Server Pages (JSPs) Robert Thornton.
Introduction to JavaServer Pages (JSP) Slides from Dr. Mark Llewellyn.
 Embeds Java code  In HTML tags  When used well  Simple way to generate dynamic web-pages  When misused (complex embedded Java)  Terribly messy.
Chapter 8 Script-free pages. Problem with scripting in JSP When you use scripting (declaration, scriplet, expressions) in your JSP, you actually put Java.
Client Scripting1 Internet Systems Design. Client Scripting2 n “A scripting language is a programming language that is used to manipulate, customize,
Introduction to Applets CS 3505 Client Side Scripting with applets.
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:
JSTL Lec Umair©2006, All rights reserved JSTL (ni) Acronym of  JavaServer Pages Standard Tag Library JSTL (like JSP) is a specification, not an.
Introduction to JavaServer Pages. 2 JSP and Servlet Limitations of servlet  It’s inaccessible to non-programmers JSP is a complement to servlet  focuses.
Java Applets. 2 Introduction to Java Applet Programs Applications are ___________________ programs –executed with Java interpreter Applet is a small program.
Lec.10 + (Chapter 8 & 9) GUI Java Applet Jiang (Jen) ZHENG July 6 th, 2005.
Pravin Yannawar, DOCS, NMU Jalgaon Basic Java : Applets 2 Objectives of This Session Identify the need for Applets Distinguish between Applets and Applications.
LECTURE 18 Java and Web Pages. Java Savvy Browser A browser capable of handling java applets: - Netscape Navigator - Microsoft Internet Explorer - Sun.
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.
CSC 2720 Building Web Applications JavaServer Pages (JSP) JSP Directives and Action Elements.
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.
Slides © Marty Hall, book © Sun Microsystems Press 1 Using JavaBeans with JSP Core Servlets & JSP book:
JSP BASICS AND ARCHITECTURE. Goals of JSP Simplify Creation of dynamic pages. Separate Dynamic and Static content.
 2008 Pearson Education, Inc. All rights reserved JavaScript: Introduction to Scripting.
Module: Software Engineering of Web Applications Chapter 2: Technologies 1.
Chapter 131 Applets and HTML Chapter Objectives learn how to write applets learn to write a simple HTML document learn how to embed an applet in.
Applets, Images, and Audio Chapter 14 CSCI CSCI 1302 – Applets, Images, and Audio2 Outline Introduction The Applet Class –The init Method –The start.
©SoftMooreSlide 1 Introduction to HTML: Forms ©SoftMooreSlide 2 Forms Forms provide a simple mechanism for collecting user data and submitting it to.
Introduction to HTML. _______________________________________________________________________________________________________________ 2 Outline Key issues.
Dave Salinas. What is XML? XML stands for eXtensible Markup Language Markup language, like HTML HTML was designed to display data, whereas XML was designed.
Chapter 6 Chapter 6 Server Side Programming (JSP) Part 1 1 (IS 203) WebProgramming (IS 203) Web Programming.
 Java Server Pages (JSP) By Offir Golan. What is JSP?  A technology that allows for the creation of dynamically generated web pages based on HTML, XML,
Chapter 14 Using JavaBeans Components in JSP Documents.
1 CSC160 Chapter 1: Introduction to JavaScript Chapter 2: Placing JavaScript in an HTML File.
Java Server Pages By: Tejashri Udavant..
Including Files and Applets in JSP Pages
INCLUDING FILES AND APPLETS IN JSP PAGES K. Phani Sirisha
Java Applets.
Java Server Pages B.Ramamurthy.
JavaScript: Introduction to Scripting
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:

Including Files & Applets in JSP Documents Parts of this presentation provided by: Vijayan Sugumaran Decision and Information Sciences Oakland University

Agenda  Using (the include directive) to include files at page translation time  Using jsp:include action to include pages at request time  Understanding why jsp:include is usually better than the include directive  Using jsp:plugin to include applets for the Java Plug-in

Including Files at Page Translation Time:  Format   Purpose  To reuse JSP content in multiple pages, where JSP content affects main page  Notes  Servers are not required to detect changes to the included file, and in practice they don't.  Thus, you need to change the JSP files whenever the included file changes.  You can use OS-specific mechanisms such as the Unix "touch" command, or 

Including Files at Request Time: jsp:include  Format   Purpose  To reuse JSP, HTML, or plain text content  To permit updates to the included content without changing the main JSP page(s)  Notes  JSP content cannot affect main page: only output of included JSP page is used  Don't forget that trailing slash  Relative URLs that starts with slashes are interpreted relative to the Web app, not relative to the server root.  You are permitted to include files from WEB-INF

jsp:include Example: A News Headline Page (Main Page) … What's New at JspNews.com Here is a summary of our three most recent news stories:

A News Headline Page, Continued (First Included Page) Bill Gates acts humble. In a startling and unexpected development, Microsoft big wig Bill Gates put on an open act of humility yesterday. More details...  Note that the page is not a complete HTML document; it has only the tags appropriate to the place that it will be inserted

A News Headline Page: Result

The jsp:param Element: Augmenting Request Parameters  Code  URL   Main page  fgColor: RED  bgColor: null  Regardless of whether you check before or after inclusion  Included page  fgColor: RED  bgColor: YELLOW

Differences Between jsp:include  jsp:include includes the output of the designated page includes the actual code  jsp:include occurs at request time occurs at page translation time  With jsp:include, the main page and the included page become two separate servlets  they become parts of a single servlet  jsp:include automatically handles changes to the included file might not (big maintenance problem!)

jsp:include vs. jsp:include Basic syntax When inclusion occursRequest timePage translation time What is includedOutput of pageContents of file Number of resulting servlets TwoOne Can included page set response headers that affect the main page? NoYes Can included page define fields or methods that main page uses? NoYes Does main page need to be updated when included page changes? NoYes

Which Should You Use?  Use jsp:include whenever possible  Changes to included page do not require any manual updates  Speed difference between jsp:include and the include directive is insignificant  The include directive ( ) has additional power, however  Snippet.jsp page defines accessCount variable   Main page can use that variable directly 

Include Directive Example: Reusable Footers (ContactSection.jsp) <%-- The following become fields in each servlet 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 "; %> This page © 2003 my-company.com. This page has been accessed times since server reboot. It was most recently accessed from at.

Reusing Footers: Typical Main Page (SomeRandomPage.jsp) … Some Random Page Information about our products and services. Blah, blah, blah. Yadda, yadda, yadda.

Reusing Footers: Result

Understanding jsp:include vs.  Footer defined the accessCount field (instance variable)  If main pages used accessCount, they would have to  Otherwise accessCount would be undefined  In this example, the main page did not use accessCount  So why did we

Options for Deploying Applets  Develop the applets with JDK 1.1 or even 1.02 (to support really old browsers).  Works with almost any browser  Uses the simple APPLET tag  Have users install version 1.4 of the Java Runtime Environment (JRE), then use JDK 1.4 for the applets.  Requires IE 5 or later or Netscape 6 or later  Uses the simple APPLET tag  Have users install any version of the Java 2 Plug-in, then use Java 2 for the applets.  Works with almost any browser  Uses ugly OBJECT and EMBED tags

Using jsp:plugin  Simple APPLET-like tag  Expands into the real OBJECT and EMBED tags  APPLET Tag   Equivalent jsp:plugin   Reminder  JSP element and attribute names are case sensitive  All attribute values must be in single or double quotes  This is like XML but unlike HTML

jsp:plugin: Source Code <jsp:plugin type="applet" code="SomeApplet.class" width="300" height="200">

jsp:plugin: Resultant HTML <object classid= "clsid:8AD9C E-11D1-B3E F499D93" width="300" height="200" codebase=" all- 1_2_2-win.cab#Version=1,2,2,0"> <embed type="application/x-java-applet;" width="300" height="200" pluginspage=" java_code="SomeApplet.class“ >

jsp:plugin: Example (JSP Code) … Using jsp:plugin <jsp:plugin type="applet" code="PluginApplet.class" width="370" height="420">

jsp:plugin: Example (Java Code) import javax.swing.*; /** An applet that uses Swing and Java 2D * and thus requires the Java Plug-in. */ public class PluginApplet extends JApplet { public void init() { WindowUtilities.setNativeLookAndFeel(); setContentPane(new TextPanel()); }  Where are.class files installed?

jsp:plugin: Example (Result)

Attributes of the jsp:plugin Element  type  For applets, this should be "applet". Use "bean" to embed JavaBeans elements in Web pages.  code  Used identically to CODE attribute of APPLET, specifying the top-level applet class file  width, height  Used identically to WIDTH, HEIGHT in APPLET  codebase  Used identically to CODEBASE attribute of APPLET  align  Used identically to ALIGN in APPLET and IMG

Attributes of the jsp:plugin Element (Cont.)  hspace, vspace  Used identically to HSPACE, VSPACE in APPLET,  archive  Used identically to ARCHIVE attribute of APPLET, specifying a JAR file from which classes and images should be loaded  name  Used identically to NAME attribute of APPLET, specifying a name to use for inter-applet communication or for identifying applet to scripting languages like JavaScript.  title  Used identically to rarely used TITLE attribute

Attributes of the jsp:plugin Element (Cont.)  jreversion  Identifies version of the Java Runtime Environment (JRE) that is required. Default is 1.2.  iepluginurl  Designates a URL from which plug-in for Internet Explorer can be downloaded. Users who don’t already have the plug-in installed will be prompted to download it from this location. Default value will direct user to Sun site, but for intranet use you might want to direct user to a local copy.  nspluginurl  Designates a URL from which plug-in for Netscape can be downloaded. Default value will direct user to Sun site, but for intranet use you might want local copy.

The jsp:param and jsp:params Elements  PARAM Tags   Equivalent jsp:param 

The jsp:fallback Element  APPLET Tag  Error: this example requires Java.  Equivalent jsp:plugin with jsp:fallback  Error: this example requires Java.

Example Using Plugin... <jsp:plugin type="applet" code="coreservlets.ShadowedTextApplet.class" width="475" height="350"> <jsp:param name="MESSAGE" value="Your Message Here" />...

Example Using Plugin: Resultant HTML... <OBJECT classid=clsid:8AD9C E-11D1-B3E F499D93 width="370" height="420" codebase=" win.cab#Version=1,2,2,0"> <EMBED type="application/x-java-applet;" width="370" height="420" pluginspage=" >...

Example Using Plugin (Continued)

Summary   Output of URL inserted into JSP page at request time  Cannot contain JSP content that affects entire page  Changes to included file do not necessitate changes to pages that use it   File gets inserted into JSP page prior to page translation  Thus, file can contain JSP content that affects entire page (e.g., import statements, declarations)  Changes to included file require you to manually update pages that use it   Simplifies writing applets that use the Java Plug-In