SlideServe
Menu
Préférences
© SlideServe · v2026

Introduction to JSP Scripting Elements and their Usage in JavaServer Pages

stacia avatar
9 diapositives · 236 Views · Oct 03, 2014

This document provides an overview of JSP (JavaServer Pages) scripting elements, detailing the various types of elements such as expressions, scriptlets, and directives. It explains how JSP expressions insert Java values into the output, allowing full access to request information at runtime. Additionally, JSP scriptlets enable the inclusion of arbitrary Java code in the page. The document also covers JSP actions, which utilize XML syntax to control servlet behavior, and illustrates the use of JavaBeans for dynamic content management. Ideal for those looking to understand JSP basics.

Introduction to JSP Scripting Elements and their Usage in JavaServer Pages - slide 1
01 / 9Introduction to JSP Scripting Elements and their Usage in JavaServer Pages
1 / 17

Télécharger la présentation

Introduction to JSP Scripting Elements and their Usage in JavaServer Pages
Une image / un lien ci-dessous est fourni (tel quel) pour télécharger la présentation

Politique de téléchargement : le contenu du site vous est fourni TEL QUEL pour votre information et votre usage personnel ; il ne peut être vendu, concédé sous licence ni partagé sur d’autres sites sans l’accord de son auteur.Le contenu vous est fourni TEL QUEL, pour votre information et votre usage personnel uniquement. Téléchargez la présentation en cliquant sur ce lien. Lors du téléchargement, si vous ne parvenez pas à télécharger une présentation, l’éditeur a peut-être supprimé le fichier de son serveur.Pendant le téléchargement, si vous ne parvenez pas à obtenir une présentation, le fichier a peut-être été supprimé par l’éditeur.

F I N

Plus de contenu associé

Transcription de la présentation
  1. Service Computing Prof. Dr. Ramin YahyapourIT & Medien Centrum3. November 2009

  2. JSP Scripting Elements –Java Expressions Current time: <%= new java.util.Date() %> • A JSP expression is used to insert Java values directly into the output. It has the following form: <%= Java Expression %> • The Java expression is evaluated, converted to a string, and inserted in the page. This evaluation is performed at run-time (when the page is requested), and thus has full access to information about the request. • Special variables: • request, the HttpServletRequest; • response, the HttpServletResponse; • session, the HttpSession associated with the request (if any); and • out, the PrintWriter used to send output to the client. Your hostname: <%= request.getRemoteHost() %>

  3. JSP Scripting Elements –Java Scriptlets • JSP scriptlets let you insert arbitrary code into the servlet method that will be built to generate the page. • Scriptlets have the following form: <% Java Code %> <% String queryData = request.getQueryString(); out.println("Attached GET data: " + queryData); %>

  4. JSP Example <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"> <HTML> <HEAD> <TITLE>Using JavaServer Pages</TITLE> </HEAD> <H1>Using JavaServer Pages</H1> <P> Some dynamic content created using various JSP mechanisms: <UL> <LI><B>Expression.</B><BR> Your hostname: <%= request.getRemoteHost() %>. <LI><B>Scriptlet.</B><BR> <% out.println("Attached GET data: " + request.getQueryString()); %> <LI><B>Declaration (plus expression).</B><BR> <%! private intaccessCount = 0; %> Accesses to page since server reboot: <%= ++accessCount %> <LI><B>Directive (plus expression).</B><BR> <%@ page import = "java.util.*" %> Current date: <%= new Date() %> </UL> </BODY> </HTML>

  5. JSP Directives <%@ directive attribute1="value1" attribute2="value2" ... attributeN="valueN" %> • JSP Directive: pagelets you do things like import classes, customize the servletsuperclass, and the like;<%@ page import="java.util.*" %> • JSP Directive: include This directive lets you include files at the time the JSP page is translated into a servlet. The directive looks like: <%@ include file="relative url" %>

  6. JSP Actions • JSP actions use constructs in XML syntax to control the behavior of the servlet engine. • Available actions include: • 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. • Most actions utilize JavaBeans which are covered later in the lecture. <jsp:useBean id="name" class="package.class" />

  7. Java Beans

  8. Bean Example import java.io.Serializable; public class BasicBean implements Serializable { boolean property; public BasicBean() { } public booleangetProperty() { return property; } public booleanisProperty() { return property; } public void setProperty(booleannewValue) { property = newValue; } }

  9. Book Bean import java.io.Serializable; public class BookBean implements Serializable { string author; public BookBean() { author = “Unnamed”; } // Property “author” public string getAuthor () { return author; } public void setAuthor(string newAuthor) { author=newAuthor; } // more properties }