; Introduction to Java Server Pages technology
Learning Center
Plans & pricing Sign in
Sign Out
Your Federal Quarterly Tax Payments are due April 15th Get Help Now >>

Introduction to Java Server Pages technology


  • pg 1
									Seminar Presented By: Swapnil Irabatti
 What is JSP?
 JSP Flow
 Comparison with existing technologies: CGI
 Comparison with existing technologies : ASP
 Comparison with existing technologies: Servlets
 Back to JSP Technology
 JSP Example: Hello World
 SimpleJSP.jsp - the Bean edition
 How it is work?
 JSP Pages content
 JSP benefits
 Resources For References
What is JSP?
 Java based technology that simplifies the developing of
  dynamic web sites
 JSP pages are HTML pages with embedded code that
  allows to access data from Java code running on the
 JSP provides separation of HTML presentation logic
  from the application logic.
JSP Flow (LifeCycle)
JSP Flow…
JSP Flow…
Comparison with existing
technologies: CGI
 CGI(Common Gateway Interface) programs (typically
  written in C or Perl) interact with the user by reading
  the user's input, HTML forms, and returning custom
  HTML pages.
 Problems:
  1: For each user request the CGI script must be loaded,
  run, and unloaded.
  2: Designed to handle only a single request: needed
  additional session support (to remember a user’s state
  between requests for a example).
 JSP vs. CGI:
    JSP can maintain state on the server between requests
    Spawns a new thread for each request
    Does not have to be loaded each time, once it has been
    Runs in a ready-loaded JVM as an extension to the web
Comparison with existing
technologies : ASP
 ASP (Active Server Pages) from Microsoft is the main
 competing technology for JSP.

 JSP & ASP are similar in the way they support the
 creation of dynamic web pages, using HTML
 templates, scripting code and components for business
   Compare me…
    Compile           Each Instance         Once

                      COM/DCOM              JSP Tags, JavaBeans, or
Code Interpretation
                                            Enterprise JavaBeans
                      Jscript or VBScript   Java

  Base Language       Microsoft only        All major web

   Platforms          ASP                   JSP
Some more….
 ASP used on Microsoft IIS pr PWS web servers. Two third
  parties, Chili!Soft andHalcyonsoft sell software that allows
  ASPs to be uses with other platforms: the main problem is
  in porting the COM components to the new platform.
 JSPs score over ASP:
    JSPs are interprted only once, to Java byte-code, and re-
     interpreted only when the file is modified
    JSPs run on all the main web servers
    JSPs provide better facilities for separation of page code and
     template data by means of JavaBeans, Enterprise JavaBeans
     and custom tag libraries.
Comparison with existing
technologies: Servlets
 Servlets are standard, server-side Java applications that
  extend the capabilities of a Web server.
 Java Servlets programming model is similar to CGI
 Servlets run inside a single process associated with a
  web server.
 Instead of creating a process for each request (as CGI)
  JVM cerates a Java thread to handle each servlet
 JVM persists beyond the life of a single request (so
  requests can share data and resources).
 Essence: Java code that outputs the HTML (out.println
 All benefits of the core Java platform: OOP model,
  cross-platform, memory management, rich collections
  of Java API’s., etc.
 Problems:
   All document contents, both static and dynamic, reside
    in program source code.
JSP Technology
 JSP technology provides a way to combine the worlds
  of HTML and Java servlet programming.
 JSP specs are built on the Java Servlet API.
 JSP supports two different styles for adding dynamic
  content to web pages:
   JSP pages can embed actual programming code
    (typically Java)
   JSP supports a set of HTML-like tags that interact with
    Java objects on the server (without the need for raw Java
    code to appear in the page).

String vfield1="Hello World";

out.println("<h1> "+vfield1);

Java Server Pages Requirements

 Java Server Pages require the

           Tomcat Jsp Container.
SimpleJSP.jsp - the Bean edition
 JSP includes tags for interacting with JavaBeans.

 JavaBean is a simply Java class that follow JavaBeans
 specs: rules for defining a Bean’s ctor & methods for
 accessing and setting their properties.
SimpleJSP.jsp - the Bean edition
<jsp:useBean id="LI" class="meatOrder.LoginMain" scope="request">

<%rtnCd = LI.Login();%>
<%if ((rtnCd.equals("1"))) { %>
                                                                    Jsp to use java class LoginMain
<jsp:forward page="Welcome.html"></jsp:forward>                     And refer to program as “LI”
  }     else {
%>                                                If rtnCd equals “1” forward
<HTML>                                            user to Welcome page
</HEAD>                                           Redisplay Login Page
<H2 align="center">Autry Greer and Son's, Inc.</H2>
<FORM method="post" name="LogIn"
<p align="center">User Id : <INPUT type="text" name="userId" size="10"></p>
<p align="center">Password: <INPUT type="password" name="passWord"
<p align="center"><INPUT type="submit" name="logIn" value="Submit"></p>
<INPUT type="hidden" name="rtncd" value=null></FORM>
JSP Example: Hello World
 In both cases the http request is:

 The response from JSP container would be:
How it is work?
 Client request for a page ending with ".jsp“.
 Web Server fires up the JSP engine.
 The JSP engine checks to see if the JSP file is new or
   The JSP engine takes the page and converts it into a Java
    servlet (by JSP parser)
   The JSP engine compiles the servlet (by standard Java
   Servlet Engine executes the new Java servlet using the
    standard API.
   Servlet’s output is transferred by Web Server as a http
JSP Pages content
 standard HTML tags & scripts (JavaScript/VBscript)
 new tags for scripting in the Java language.

   Expressions:
   <%=expression %>
  For Example:
       <%= fact(12) %>
       <%= (hours <12) ? “AM” : “PM” %>
       <%= Math.pow(radius, 2) %>
JSP Pages content…
  Scriptlets:
    <% scriptlet %>
    <jsp:scriptlet> scriptlet </jsp:scriptlet>

  Declarations:
    <%! declaration (s) %>
    <jsp:declaration> declaration(s) </jsp: declaration>
JSP Pages content…
 JSP directives – is a set of tags for providing the JSP container
  with page specific instructions for how the document should be
  processed. Directives affect global properties of the JSP page.
       <%@ page attr1=“val1” attr2=… %>

 Comments –for adding documentation
    Comments that will be in the output:
        <!-- comment -->
    JSP comments
        <%-- comment --%>
    Scripting language comments:
        <% /* comment */ %>
JSP Pages content…
JSP Pages content…
 Bean’s tags
  allows JSP pages to call reusable components called
  JavaBeans components.
  The tag <jsp:useBean> syntax is:
<jsp:useBean id="Bean_name" scope="scope_value"
  class="class_name" beanName="ser_filename"
  type="class_or_interface_name" > properties
<jsp:setProperty> tag syntax is:
  <jsp:setProperty name="property_name"
       property="property_value" />
JSP benefits
 Java-based technology
 Vendor-neutral
 Full access to underlying Java platform
 Performance
 Reusable components (JavaBeans)
 Separating presentation and implementation
 Sun JSP 1.1 Specs and description
 Server Side Java Resource Site
 IBM education courses
 JSP resource index
 JSP insider

To top