1 / 9

Service Computing

Service Computing. Prof. Dr. Ramin Yahyapour IT & Medien Centrum 3 . Novem ber 2009. JSP Scripting Elements – Java Expressions. Current time: <%= new java.util.Date () %>.

stacia
Download Presentation

Service Computing

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  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 }

More Related