Bb: Javaserver Pages (jsp)

  • Uploaded by: mohanraop
  • 0
  • 0
  • May 2020
  • PDF

This document was uploaded by user and they confirmed that they have the permission to share it. If you are author or own the copyright of this book, please report to us by using this DMCA report form. Report DMCA


Overview

Download & View Bb: Javaserver Pages (jsp) as PDF for free.

More details

  • Words: 1,169
  • Pages: 19
BB: JavaServer Pages (JSP) ATS Application Programming: Java Programming

© Accenture 2005 All Rights Reserved

Course Code #Z16325

Objectives This review session will cover JSP. Included in this review:  Overview  What is a JSP Page?  Syntax Summary  Template Text: Static HTML  JSP Scripting Elements  JSP Directives  JSP Actions  Example using Scripting and Directives ©2004 Accenture All Rights Reserved.  Resources

© Accenture 2005 All Rights Reserved

2

Overview Choosing a server-side language used to be easy. Before, CGI was the only scripting option out there. Developers could write their own server extensions, but few were up to the challenge to address the following difficulties: ©2004 Accenture All Rights Reserved.

© Accenture 2005 All Rights Reserved

3

Overview (Cont.) In response to ASP, Sun Microsystems gave the world JavaServer Pages (JSP) technology, based entirely upon Sun's popular Java programming language, it gives developers the advantages of developing in Java in a more relaxed, script-like environment. Behind the scenes, JSP pages are dynamically ©2004 Accenture All Rights Reserved. assembled

© Accenture 2005 All Rights Reserved

4

What is a JSP Page? A text document that contains two types of information:  Static data (which can be expressed in any text-based format (such as HTML, SVG, WML, and XML)  JSP elements (which construct dynamic content) .jsp = file extension for a JSP Page source file ©2004 Accenture All Rights Reserved. © Accenture 2005 All Rights Reserved

5

Summary of Syntax Basics

JSP Element JSP Expression JSP Scriptlet

Syntax <%= expression %> <% code %>

JSP Declaration

<%! code %>

JSP page Directive

<%@ page att="val" %>

JSP include Directive

<%@ include file="url" %>

JSP Comment

<%-- comment --%>

The jsp:include Action The Expression Language (EL)

<jsp:include page="relative URL" flush="true"/> ${ }

Interpretation Expression is evaluated and placed in output. Code is inserted in service method. Code is inserted in body of Servlet class, outside of service method. Directions to the Servlet engine about general setup. A file on the local system to be included when the JSP page is translated into a Servlet. Comment; ignored when JSP page is translated into Servlet. Includes a file at the time the page is requested. Expressions that retrieve the value of object properties.

<jsp:useBean att=val*/> or <jsp:useBean att=val*> The jsp:useBean Action Find or build a Java Bean. ... The jsp:setProperty Set bean properties, either explicitly or by designating <jsp:setProperty att=val*/> Action that value comes from a request parameter. <jsp:getProperty The jsp:getProperty name="propertyName" Retrieve and output bean properties. Action value="val"/> <jsp:forward The jsp:forward Action Forwards request to another page. page="relative URL"/> <jsp:plugin Generates OBJECT or EMBED tags, as appropriate to the attribute="value"*> The jsp:plugin Action browser type, asking that an applet be run using the ... Java Plugin. ©2004 Accenture All Rights Reserved. 6

© Accenture 2005 All Rights Reserved

Template Text: Static HTML

A large percent of your JSP page just consists of static HTML, known as Template Text. ©2004 Accenture All Rights Reserved. © Accenture 2005 All Rights Reserved

7

JSP Scripting Expressions: A JSP expression is used to insert Java values directly into the output. <%= Java Expression %> The following shows the date/time that the page was requested. ©2004 Accenture All Rights Reserved. © Accenture 2005 All Rights Reserved

8

JSP Scripting Scriptlets: JSP Scriptlets let you insert arbitrary code into the Servlet Method. <% Java Code %> <% String queryData = request.getQueryString(); Out.println(“Attached GET data: “+ ©2004 Accenture All Rights Reserved. 9 © Accenture 2005 All Rights Reserved

JSP Scripting Scriptlets

Before conversion: <% if (Math.random() < 0.5) { %> Have a nice day! <% } else { %> Have a lousy day! <% } %>

After conversion: if (Math.random() < 0.5) { out.println(“Have a nicew day!”); } else { out.println(“Have a lousy day!”); }

©2004 Accenture All Rights Reserved. © Accenture 2005 All Rights Reserved

10

JSP Scripting Declarations A JSP declaration lets you define methods or fields that are inserted into the main body of the Servlet class. <%! Java Code %> <%! Private int accessCount = 0; %> Access to page©2004 since server reboot: Accenture All Rights Reserved. © Accenture 2005 All Rights Reserved

11

JSP Directives A JSP directive affects the overall structure of the servlet class. Name Description <% directive attribute=“value” %> Page Lets you import classes and customize the Servlet superclass, and the like. Includ Lets you insert a file into the e Servlet class at the time the JSP file is translated into ©2004 Accenture All Rights Reserved. 12 a Servlet.

© Accenture 2005 All Rights Reserved

JSP Directives session

true (active) / false (disable) <%@ page session = “true” %> sizekb (buffer size in Kilobyte) / none buffer (disable) buffer) /=false (exception) autoflush true <%@ (flush page buffer “none” %> <%@ page autoFlush = “true” %> extends=“package.class” extends <%@ page extends =“com.taglib…” %> info = “message” info <%@ page info = “java.com test page, errorPage errorpage test“%>= “URL” <%@ page errorPage = (error page) / false (no isErrorPa true “/error/error.jsp” %> error page) <%@ page isErrorPage = “true”%> ge language language = “java” <%@ page language = “java” %> contentTy contentType=”ctinfo” <%@ page contentType = “description” pe import=”importList” import %>©2004 Accenture All Rights Reserved. <%@ page import = “package” %> © Accenture 2005 All Rights Reserved

13

JSP Directives Include: This directive lets you include files at the time the JSP page is translated into a Servlet <TITLE>JavaServer Pages (JSP) ©2004 Accenture All Rights Reserved.

© Accenture 2005 All Rights Reserved

14

JSP Actions JSP Actions are used to control the behavior of the Servlet Engine.

• jsp:include - Include a file at the time the page is requested. • jsp:useBean - Find or instantiate a JavaBean. • jsp:setProperty - Set the property of a JavaBean. • jsp:getProperty - Insert the property of a JavaBean into the output. • jsp:forward - Forward the requester to a new page. • jsp:plugin - Generate browser-specific code that makes an OBJECT or EMBED tag for the Java plugin. ©2004 Accenture All Rights Reserved.

© Accenture 2005 All Rights Reserved

15

Example using Scripting & Directives

<TITLE>Using JavaServer Pages

Using JavaServer Pages

  • Expression.
    Your hostname: <%= request.getRemoteHost() %>.
  • Scriptlet.
    <% out.println("Attached GET data: " + request.getQueryString()); %>
  • Declaration (plus expression).
    <%! private int accessCount = 0; %> Accesses to page since server reboot: <%= ++accessCount %>
  • Directive (plus expression).
    <%@ page import = "java.util.*" %> Current date: <%= new Date () %>
© Accenture 2005 All Rights Reserved

©2004 Accenture All Rights Reserved.

16

Example using Scripting & Directives Output

©2004 Accenture All Rights Reserved. © Accenture 2005 All Rights Reserved

17

Helpful Websites:

Resources

http://javaboutique.internet.com/tutorials/JSP/  http://java.sun.com/j2ee/1.4/docs/tutorial  http://java.sun.com/products/jsp/download.htm 

http://java.sun.com/products/jsp  http://www.roseindia.net/jsp/introduction.shtm 



http://java.sun.com/developer/onlineTraining/J ©2004 Accenture All Rights Reserved.

© Accenture 2005 All Rights Reserved

18

Questions

©2004 Accenture All Rights Reserved. © Accenture 2005 All Rights Reserved

19

Related Documents

Jsp
April 2020 36
Jsp
May 2020 27
Jsp
May 2020 14
Jsp
May 2020 14

More Documents from ""

Threads
May 2020 26
Jsp
May 2020 21
Servlet
May 2020 21
Ajax
May 2020 36
Wml
May 2020 18