Hello, Welcome to JavaServer Pages! <% // continue scriptlet } // end if else { %> Type your first name and press Submit <% // continue scriptlet } // end else %>"> Hello, Welcome to JavaServer Pages! <% // continue scriptlet } // end if else { %> Type your first name and press Submit <% // continue scriptlet } // end else %>">

Presentation is loading. Please wait.

Presentation is loading. Please wait.

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.

Similar presentations


Presentation on theme: "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."— Presentation transcript:

1 Java Server Pages CS-422

2 What are JSPs A logical evolution of java servlets –most servlets dynamically create HTML and integrate it with some computational and database output Servlets on their own had some pretty stiff competition form PHP, ASP and ColdFusion –these technologies for the most part (especially ColdFusion) don’t need a programmer; ASP and PHP definitely have a programming language in their background but scripting in VBScript or PHP is still easier than Java some one at Sun recognized that a servlet was just some Java with HTML embedded in it, and thought: why not embed some Java in regular HTML; then create a class that will scan through it and make the source code for a servlet, then compile it and deploy it The Java Server Page is born

3 An Example... Processing "get" requests with data <% // begin scriptlet String name = request.getParameter( "firstName" ); if ( name != null ) { %> Hello, Welcome to JavaServer Pages! <% // continue scriptlet } // end if else { %> Type your first name and press Submit <% // continue scriptlet } // end else %>

4 The rendered screen(s)... After entering Dick...

5 Embedding Java in HTML Embedding Java in HTML is pretty simple; the lead is taken from PHP and ASP; we’ll make a special escape character “ ” the tag pair are used for defining scriptlets; a sequences of Java statements –scriptlets are used to glue the parts of your jsp together (see prev. example) the tag pair is used for Java expression evaluation –ex will be replaced with the current Date/Time

6 JSP Directives page taglib include

7 page directive Language – “scriptingLanguage” Extends – “classname” Import – “importList” – java.lang.*, javax.servlet.*, javax.servlet.jsp.*, and javax.servlet.http.* are imported implicitily Session “true|false” Buffer – “none|sizekb” autoFlush- “true|false” isThreadSafe – “true|false” Info – “info_text” errorPage – “error_URL” isErrorPage – “true|false” contentType – “contentInfo” pageEncoding – “pageEncodingInfo”

8 taglib directive Import a taglib into the page Associate taglib with a URI Map the URI to,a prefix for use within the page

9 include directive Allows the inclusion of another file into the defining page Happens at translation time.

10 JSP Actions (Tags) JSP provides a set of standard actions to help you with commonly done tasks: –

11 Attributes: –page - specifies the relative URI path to the resource to include –flush - must be “true” ; specifies whether the buffer should be flushed after the include is performed – –use this action to include dynamic content; it will be included each time it is included there is also an include directive – –use this for including static content, is included only once

12 Allows you to forward processing to another JSP, as soon as processing is forwarded the processing of the curreent JSP is terminated can be used in conjunction with to forward parameter information to the forwarded JSP ” />

13 Adds an applet or JavaBean to a Web page in the form of a browser=specific object or embed XHTML element. It also allows the client to download and install the java Plug-in if it is not already present. Attributes: –type - bean or applet –code - Class that represents the component –codebase- location of the class specified in the code attribute and the archives specified in the archives attribute –align - Alignment od the component (left,right,center) –archive - space separated list of archives (JARS) containing resources –height - component height in pixels –hspace - number of pixels to right and left of component –jreversion - version of the JRE required –name - name of component –vspace - number of pixels above and below the component –title - Text describing the component –width - component width in pixels or percent –nspluginurl - location of plugin for Netscape Navigator –iepluginurl - location of plugin for Internet Explorer

14 Enables a JSP to manipulate or use a JavaBean. The action creates or locates an existing object for use in the JSP. Attributes: –id - the name used to manipulate the Java object (case sensitive) –scope - page, request,session,or application (default is page) –class - fully qualified class name of the Java object –beanName - The name that can be used with method instantiate of class java.beans.Beab to load a JavaBean into memory. –Type - type of JavaBean, can be same as class attribute, a superclass of that type or an interface implemented by that type

15 Used to set Bean property values Attributes: –name - Id of the Bean for which a property is to be set –property - name of the property to set –param - specify which request parameter is to be used –value - the value to assign to a Bean proberty

16 retrieve the value of a Bean property attributes: –name - the name of the Bean –property - the name of the property to retrieve


Download ppt "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."

Similar presentations


Ads by Google