JSP.pptx ROOPAM

download JSP.pptx ROOPAM

of 33

Transcript of JSP.pptx ROOPAM

  • 8/8/2019 JSP.pptx ROOPAM

    1/33

    JSPJSP

    JavaServerJavaServer

    PagesPages

  • 8/8/2019 JSP.pptx ROOPAM

    2/33

    PagesPages The Typical WebThe Typical Web

    server, differentserver, differentclients connectingclients connecting

    via the Internet tovia the Internet to

    a Web server. Ina Web server. In

    this example, thethis example, theWeb serverisWeb serveris

    running on Unixrunning on Unix

    and is the veryand is the very

    popular Apachepopular ApacheWeb serverWeb server..

  • 8/8/2019 JSP.pptx ROOPAM

    3/33

    First static web pages were displayed.First static web pages were displayed.

    Afterwards Perl and C were languages used onAfterwards Perl and C were languages used on

    the web server toprovide dynamiccontent.the web server toprovide dynamiccontent.Soon most languages includingSoon most languages including VisualbasicVisualbasic,,

    Delphi, C++ and Java could be used to writeDelphi, C++ and Java could be used to write

    applications that provided dynamiccontent usingapplications that provided dynamiccontent using

    data from text files or database requests.data from text files or database requests.

    These were known as CGI server sideThese were known as CGI server side

    applications.applications.

    ASP was developed by Microsoft to allow HTMLASP was developed by Microsoft to allow HTMLdevelopers to easilyprovide dynamiccontentdevelopers to easilyprovide dynamiccontent

    supported as standard by Internet Informationsupported as standard by Internet Information

    Server (IIS).Server (IIS).

    JSP was developed by Sun Microsystems.JSP was developed by Sun Microsystems.

  • 8/8/2019 JSP.pptx ROOPAM

    4/33

    Introduction to Java ServerIntroduction to Java Server

    PagesPages

    JavaServerJavaServer Pages (JSP) is a technologyPages (JSP) is a technology

    based on the Java language and enablesbased on the Java language and enables

    the development ofdynamic web sites.the development ofdynamic web sites.JSP was developed by Sun MicrosystemsJSP was developed by Sun Microsystems

    to allow server side development. JSPto allow server side development. JSP

    files are HTML files with special Tagsfiles are HTML files with special Tags

    containing Java source code that providecontaining Java source code that providethe dynamiccontent.the dynamiccontent.

  • 8/8/2019 JSP.pptx ROOPAM

    5/33

  • 8/8/2019 JSP.pptx ROOPAM

    6/33

    JSP source code runs on the web serverin the JSP Servlet Engine. The JSP

    Servlet engine dynamically generates the HTML and sends the HTML output to

    the client's web browser

  • 8/8/2019 JSP.pptx ROOPAM

    7/33

    Why use JSP?Why use JSP?

    JSP is easy to learn and allows developers toJSP is easy to learn and allows developers to

    quicklyproduce web sites and applications in anquicklyproduce web sites and applications in an

    open and standard way. JSP is based on Java,open and standard way. JSP is based on Java,

    an object oriented language. JSP offers a robustan object oriented language. JSP offers a robustplatform for web development.platform for web development.

    Main reasons to use JSPMain reasons to use JSP::Multiplatform (windows nMultiplatform (windows n unixunix))

    Component reuse by usingComponent reuse by using JavabeansJavabeans and EJB.and EJB.

    Advantages ofJava.Advantages ofJava.

  • 8/8/2019 JSP.pptx ROOPAM

    8/33

    What are Java ServerWhat are Java Server

    Pages?Pages?Conceptually seen as scriptsConceptually seen as scripts

    Adopt more procedural style ofcodingAdopt more procedural style ofcoding

    OO techniques are still possibleOO techniques are still possibleAdopt a modern web development styleAdopt a modern web development style

    Simplified syntaxSimplified syntax

    Many builtMany built--in shortin short--cutscuts

    Text files containingText files containing

    HTMLHTML

    Java codeJava code

  • 8/8/2019 JSP.pptx ROOPAM

    9/33

    You can take one JSP file and move it to another platform, webYou can take one JSP file and move it to another platform, web

    server or JSPserver or JSP ServletServlet engine.engine.

    Moving JSP file from one platform to another.Moving JSP file from one platform to another.

  • 8/8/2019 JSP.pptx ROOPAM

    10/33

    HTML and graphics displayed on the web browser are classed as theHTML and graphics displayed on the web browser are classed as the

    presentation layer..presentation layer..

    JavaServer Pages

    JSP

    Implementation

    Javadevelopers

    presentation

    web designers

  • 8/8/2019 JSP.pptx ROOPAM

    11/33

    Advantages ofAdvantages of ServletsServlets

    EfficientEfficient: threads instead ofOS processes, one: threads instead ofOS processes, oneservletservlet copy, persistencecopy, persistence

    ConvenientConvenient: lots ofhigh: lots ofhigh--levellevel utilitiesutilities

    PowerfulPowerful: talking to server, sharing data, pooling,: talking to server, sharing data, pooling,persistencepersistence

    PortablePortable: run on virtually all operating systems: run on virtually all operating systemsand serversand servers

    SecureSecure: no shell escapes, no buffer: no shell escapes, no bufferoverflowsoverflowsInexpensiveInexpensive: inexpensive plug: inexpensive plug--ins ifins ifservletservletsupport not bundledsupport not bundled

  • 8/8/2019 JSP.pptx ROOPAM

    12/33

    Pro l ithPro l ith r l tr l t

    r l tr l t d lopment requires highdevelopment requires high--level oflevel of

    understanding ofmanyconceptsunderstanding ofmanyconcepts

    Too much overhead in development cycleToo much overhead in development cycle(implementation n design concatenated)(implementation n design concatenated)

    Limited uiltLimited uilt--in productivitymechanismsin productivitymechanisms

    Clunkysyntax (Clunkysyntax (unorganisedunorganised))

  • 8/8/2019 JSP.pptx ROOPAM

    13/33

    Advantages f J PAdvantages f J P

    Versus ASP: better language for dynamicpart,Versus ASP: better language for dynamicpart,

    portableportable

    Versus PHP: better language for dynamicpartVersus PHP: better language for dynamicpart

    Versus pureVersus pure servletsservlets: more convenient tocreate: more convenient tocreate

    HTMLHTML

    Versus SSI: much more flexible and powerfulVersus SSI: much more flexible and powerful

    Versus JavaScript: serverVersus JavaScript: server--sideside,, richerricher languagelanguageVersus static HTML: dynamicfeaturesVersus static HTML: dynamicfeatures

  • 8/8/2019 JSP.pptx ROOPAM

    14/33

    JSP orJSP or ServletsServlets: How do I choose?: How do I choose?

    Servlets JSP

    Servlets usageMinimal HTML generation

    Somewhat constant logic

    Complex Java logic

    JSP usageComplex HTML

    Dynamic logic

    simple Java logic

    Servlet disadvantages

    Nopre-built set ofreusable

    componentsHard to maintain when HTML

    intensive

    Require Java expertise

    Development cycle

    JSP disadvantages

    Can get messy

    Can be misused

    Servlet benefits

    Complete controlAdvanced development

    Flexible

    JSP benefits

    Pre-built componentsExpression language

    Convenience features

    Requires minimal Java knowledge

    Development cycle

    Flexible

  • 8/8/2019 JSP.pptx ROOPAM

    15/33

    JSP rchitect reJSP rchitect re

    JSPs re b ilt on topofSUN'sJSPs re b ilt on topofSUN's servletservlet technology.technology.

    JSPs reessential an HTML page with special JSP tagsJSPs areessential an HTML page with special JSP tags

    embedded. TheseJSP tags can contain Java code.embedded. TheseJSP tags can contain Java code.

    TheJSPfileextension is .TheJSPfileextension is .jspjsp rather than .rather than .htmhtm or .html.or .html.TheJSPengineparses the .TheJSPengineparses the .jspjsp and creates aJavaand creates aJava

    servletservlet sourcefile. It then compiles the sourcefileintoasourcefile. It then compiles the sourcefileintoa

    class file, this is done thefirst timeand this why theJSPclass file, this is done thefirst timeand this why theJSP

    is probably slower thefirst timeit is accessed.is probably slower thefirst timeit is accessed.

    Any timeafter this the special compiledAny timeafter this the special compiled servletservlet isis

    executed and is therefore returns faster.executed and is therefore returns faster.

  • 8/8/2019 JSP.pptx ROOPAM

    16/33

  • 8/8/2019 JSP.pptx ROOPAM

    17/33

    Steps required for a JSP request:Steps required for a JSP request:

    1.1. The user goes to a web site made using JSP. The user goes to aThe user goes to a web site made using JSP. The user goes to a

    JSP page (ending with .JSP page (ending with .jspjsp). The web browser makes the request). The web browser makes the request

    via the Internet.via the Internet.

    2.2. The JSP request gets sent to the Web server.The JSP request gets sent to the Web server.

    3.3. The Web serverThe Web server recognisesrecognises that the file required is special (.that the file required is special (.jspjsp),),therefore passes the JSP file to the JSPtherefore passes the JSP file to the JSP ServletServlet Engine.Engine.

    4.4. Ifthe JSP file has been called the first time, the JSP file is parsed,Ifthe JSP file has been called the first time, the JSP file is parsed,

    otherwise go to step 7.otherwise go to step 7.

    5.5. The next stepis to generate a specialThe next stepis to generate a special ServletServlet from the JSP file. Allfrom the JSP file. All

    the HTML required is converted tothe HTML required is converted toprintlnprintln statements.statements.6.6. TheThe ServletServlet source code is compiled into a class.source code is compiled into a class.

    7.7. TheThe ServletServlet is instantiated, calling the init and service methods.is instantiated, calling the init and service methods.

    8.8. HTML from theHTML from the ServletServlet output is sent via the Internet.output is sent via the Internet.

    9.9. HTML results are displayed on the user's web browser.HTML results are displayed on the user's web browser.

  • 8/8/2019 JSP.pptx ROOPAM

    18/33

    Installing a softwareInstalling a software

    Java 2 Standard addition SoftwareJava 2 Standard addition Software

    Development Kit(J2SE SDK)Development Kit(J2SE SDK)

    Apache Jakarta TomcatApache Jakarta Tomcat Tomcat is known asTomcat is known as servletservlet container. In java,container. In java,

    world,world, servletservlet containeris responsible forcontaineris responsible for

    receiving web requests and passing them toreceiving web requests and passing them to

    the java web application.the java web application.

  • 8/8/2019 JSP.pptx ROOPAM

    19/33

  • 8/8/2019 JSP.pptx ROOPAM

    20/33

  • 8/8/2019 JSP.pptx ROOPAM

    21/33

  • 8/8/2019 JSP.pptx ROOPAM

    22/33

  • 8/8/2019 JSP.pptx ROOPAM

    23/33

  • 8/8/2019 JSP.pptx ROOPAM

    24/33

  • 8/8/2019 JSP.pptx ROOPAM

    25/33

  • 8/8/2019 JSP.pptx ROOPAM

    26/33

  • 8/8/2019 JSP.pptx ROOPAM

    27/33

  • 8/8/2019 JSP.pptx ROOPAM

    28/33

  • 8/8/2019 JSP.pptx ROOPAM

    29/33

    JSP Syntax TagsJSP Syntax Tags

    6 primary JSP syntax tags6 primary JSP syntax tagsCommentComment

    Server side comment styleServer side comment style

    Single or multiSingle or multi--lineline

    DirectiveDirective

    Used to describe page characteristicsUsed to describe page characteristics

    Provides execution information tocontainerProvides execution information tocontainer

    DeclarationDeclaration

    Used to declare variables or methodsUsed to declare variables or methods

    Can inadvertentlycreate a nonCan inadvertentlycreate a non--thread safe JSPthread safe JSP

  • 8/8/2019 JSP.pptx ROOPAM

    30/33

    JSPSyntax Tags [cont.]JSPSyntax Tags [cont.]

    6 primaryJSPsyntax tags6 primaryJSPsyntax tags

    ScriptletScriptlet

    Used to apply business logic to HTML generationUsed to apply business logic to HTML generationTypicallyintermixed with HTML throughout pageTypicallyintermixed with HTML throughout page

    ExpressionExpression

    Used to convert Java value into HTML textUsed to convert Java value into HTML text

    Easy way to write out a valueEasy way to write out a value

    JSPactionJSPaction

    Predefined executable tagsPredefined executable tags

    SimplifiesJSPsyntaxSimplifiesJSPsyntax

  • 8/8/2019 JSP.pptx ROOPAM

    31/33

    JSP evelopmentJSP evelopment

    Like writing an HTML documentLike writing an HTML document

    JSPhas its own set of tagsJSPhas its own set of tags

    Contains HTML presentation logicContains HTML presentation logic

    Includes conditional Java logicIncludes conditional Java logic

    CanincludeJavaScript or XMLCanincludeJavaScript or XML

    Normally stored in a .Normally stored in a .jspjsp filefile

    Handles requestHandles request

    Generates responseGenerates response

  • 8/8/2019 JSP.pptx ROOPAM

    32/33

    FreeFree ServletServlet and S Softwareand S Software

    Tomcat: http://jakarta.apache.org/

    JSWDK:

    http://java.sun.com/products/servlet/download.ht

    ml

    JRun: http://www.allaire.com/products/jrun/

    ServletExec: http://newatlanta.com/

    LiteWebServer: http://www.gefionsoftware.com/Java Web Server:

    http://www.sun.com/software/jwebserver/try/

  • 8/8/2019 JSP.pptx ROOPAM

    33/33

    Thank YouThank You

    Queries???Queries???