SlideShare a Scribd company logo
1 of 87
Download to read offline
Module 4: JSP Basics


Thanisa Kruawaisayawan
 Thanachart Numnonda
 www.imcinstitute.com

                         1
Objectives

 What is JSP?
 What are the Advantages of JSP?
 Elements of a JSP files and tags
 JSP and Java Beans
 Link Servlet and JSP




                                     2
What is JSP?
   A way to create dynamic web pages
   A text-based documents capable of returning dynamic content
    to a client browser
   Server side processing
   Based on Java Technology
     Large library base
     Platform independence
   Contains HTML, XML, programming code, and JSP tags
    (HTML and XML tags) allowing access to components such
    as JavaBeans
   Separates the graphical design from the dynamic content

                                                                  3
Compiled into a Servlet




myJSP.jsp     myJSP_jsp.java   myJSP_jsp.class

                jspInit()
              _jspService()
              jspDestroy()


                                                 4
The JSP Life Cycle
   The life cycle of a JSP can be split into approximately
    four phases:
       Translation
            The JSP engine will translate the JSP into its page
            implementation servlet and compile it into a class file
       Initialization
           The JSP engine will need to load the generated class file and create
            an instance of the servlet
       Servicing
           The methods jspInit() and _jspService() will be called
       Destruction
           The method jspDestroy() will be called


                                                                               5
How Do JavaServer Pages Work?
         HTTP



                   WEB       JSP
Client            SERVER    ENGINE       Database



                                     JSPs are
                                     processed here

                JSP Files

                                                      6
JSP Page Translation Procedure




                                 7
What are the Advantages of JSP?
   Content and display logic are separated.
   Simplify development with JSP, JavaBeans and
    custom tags.
   Supports software reuse through the use of
    components.
   Recompile automatically when changes are made to
    the source file.
   Easier to author.
   Platform-independent


                                                       8
helloWorld.jsp




                 9
What does a JSP look like?
   Three main JSP constructs:
       Directives
           Allows one to control structure of the servlet
       Scripting Elements
           Used to include Java code
       Actions
           Specific tags that affect the runtime behavior of the
            JSPs


                                                                    10
Fixed Template    An Example
     data

<HTML>
<HEAD><TITLE>MyFirstProgram.jsp</TITLE></HEAD>
<BODY>                                            JSP
<!-- MyFirstProgram.JSP -->                    Directive

<%@ page import = "java.util.Date" %>               JSP
                                                  Scripting
<% out.println("Hello there!"); %><BR>
                                                JSP Action
<jsp:useBean id="name" scope="page"
  class="myBean.SimpleBean" />
</BODY>
</HTML>


                                                        11
Directives
   JSP page have the following three types of directives:
       page
       include
       taglib
   All three directive types must be declared between <
    %@ and %> directive delimiters and take the following
    form:
    <%@ directive {attribute="value"}* %>



                                                             12
The page Directive
   The page directive is a JSP tag that you will use in almost
    every JSP source file.
   The page directive gives instructions to the JSP container that
    apply to the entire JSP source file.
   page might specify the scripting language used in the JSP
    source file, packages the source file would import, or the error
    page called if an error or exception occurs.
   You can use the page directive anywhere in the JSP file, but
    it’s good coding style to place it at the top of the file.


                                                                       13
Attributes of The page Directive
   language
       Currently, JSP 2.0 only supports a value of "Java"

   extends
       Java class that will form the superclass of the JSP page’s servlet.

   import
     Indicates the classes available for use within the scripting environment
     The default import list is as follows:
            javax.servlet.jsp.* and
            javax.servlet.http.*

   session
       Indicates that the page requires an HttpSession
       The default value is "true"


                                                                                 14
Attributes of The page Directive
                      (cont.)
   buffer
     Specifies the buffering model for JspWriter used to handle the response
     The default value isn’t less than 8 KB.


   autoFlush
     Indicate whether the output buffer should be flushed automatically when
      full
     The default value is "true"


   isThreadSafe
     Indicates the threading model to be used by the JSP
     The default value is "true"


   info
     Can be used to provide any arbitrary string
     Returned via a call to the page servlet’s getServletInfo() method

                                                                                15
Attributes of The page Directive
                      (cont.)
   isErrorPage
     Indicates whether or not the current JSP is intended to be an error page
     The default value is "false"


   errorPage
       Defines the URL that any throwable objects are forwarded for error
        processing

   contentType
     Defines the character encoding for the JSP page and MIME type of the
      response
     The default value for the type is "text/html" and for the charset it’s
        "ISO-8859-1"



                                                                                 16
Attributes of The page Directive
                      (cont.)
   pageEncoding
       Defines the character encoding for the JSP page
       The default value is "ISO-8859-1"

   isELignored
       Defines whether the EL (Expression Language) expressions are evaluated
        for the JSP page
       The default value is "false"




                                                                                 17
Examples of The page Directive
  <%@ page language="java" %>
   <%@ page language="java" %>
  <%@ page import="java.util.*, java.text.*" %>
   <%@ page import="java.util.*, java.text.*" %>
  <%@ page extends="Servlet1" %>
   <%@ page extends="Servlet1" %>
  <%@ page session="true" %>
   <%@ page session="true" %>
  <%@ page buffer="16kb" %>
   <%@ page buffer="16kb" %>
  <%@ page autoFlush="true" %>
   <%@ page autoFlush="true" %>
  <%@ page isThreadSafe="false" %>
   <%@ page isThreadSafe="false" %>
  <%@ page info="First JSP" %>
   <%@ page info="First JSP" %>
  <%@ page isErrorPage="false" %>
   <%@ page isErrorPage="false" %>
  <%@ page errorPage="ErrorPage.jsp" %>
   <%@ page errorPage="ErrorPage.jsp" %>
  <%@ page contentType="text/html" %>
   <%@ page contentType="text/html" %>
  <%@ page pageEncoding="ISO-8859-1" %>
   <%@ page pageEncoding="ISO-8859-1" %>
  <%@ page isELIgnored="false" %>
   <%@ page isELIgnored="false" %>



                                                   18
The include Directive
   The include directive inserts the contents of another
    file in the main JSP file, where the directive is located
    .
   It’s useful for including copyright information,
    scripting language files, or anything you might want t
    o reuse in other applications.
   The included file does not contain <html> or <body>
    tags, because these tags would conflict with the same
    tags in the calling JSP file.


                                                            19
Example
<!-- dukeBanner.html -->
<img src="Duke.png">
____________________________________________________

<%-- welcome.jsp --%>
<%@ include file=“dukeBanner.html" %>




                                                       20
Scripting Elements
 Comments
 Declarations
 Scriptlets
 Expressions




                                 21
Comments
   JSP comments may be declared inside a JSP as
    follows:
    <%-- This is JSP comment. --%>

   HTML comments
    <!-- This is HTML comment. -->

   They are the same?


                                                   22
Declarations
   Declarations are the definition of class-level variables
    and methods that are used in a JSP.
   The general syntax is as follows:
        <%! Declaration; %>


   Example:
     <%! private int count; %>
     <%! Date now = new Date(); %>
     <%!
          private int sum(int a, int b) {
           …return a+b;
          }
      %>
                                                               23
JSP Scripting Elements
      Points to remember about declarations:
   Declarations do not produce any printable results.
   Variables are initialized when the JSP is initialized.
   Such variables are available to other declarations,
    expressions, and scriptlets.
   Variables created through declarations become
    instance variables.
   Simultaneous users of the JSP share the same
    instance of the variable.
   Class variables and methods can be declared in a
    declaration block.                                       24
Scriptlets
 Scriptlets are small blocks of source code
  contained within the <% and %>
 The general syntax is as follows:
    <% scriptlet_source; %>
   Example
      <% out.println(++count); %>




                                               25
Example
 <%! int count; %>
<% out.println(++count); %>




                              They are
                              the same?




 <% int count = 0; %>
<% out.println(++count); %>
                                    26
Implicit Objects
 Server-side objects are defined by the JSP
  container
 They are always available in a JSP, without
  being declared
 These objects determine:
       how to accept the request from the browser
       how to send the response from the server
       how session tracking can be done
                                                     27
Implicit Objects (cont.)
  Objects                        class                   scope
  request     javax.servlet.http.HttpServletRequest     request

 response     javax.servlet.http.HttpServletResponse      page

  session     javax.servlet.http.HttpSession            session

application   javax.servlet.ServletContext             application

    out       javax.servlet.jsp.JspWriter                 page

PageContext   javax.servlet.jsp.PageContext               page

  config      javax.servlet.ServletConfig                 page

   page       java.lang.Object                            page

exception     java.lang.Throwable                      application


                                                                  28
Expressions
 Evaluate a regular Java expression and return a
  String or be convertible to a String result
 The general syntax is as follows:
    <%= expression %>
   Example
    <%= ++count %>
   JSP expressions don’t require a closing
    semicolon.

                                                    29
A Simple Web Application




                           30
Conditional Statements
<%! int count; %>

This page has been accessed <%= ++count %> time(s). <BR>

<% if (count == 1) { %>
     Welcome, you are the first visitor to our site.<BR>
<% } else { %>
     You are not the first visitor to our site.<BR>
<% } %>
   Please do visit us again. Thank you!




                                                           31
Iterative Statements (For)
<% for (int i=0; i<5; i++) { %>
     Welcome to our site! <BR>
<% } %>




                                      32
Iterative Statements (While)
<% java.util.Enumeration enum1 = request.getHeaderNames();
  %>
<% while (enum1.hasMoreElements()) { %>
   <%= enum1.nextElement() %> <BR>
<% } %>




                                                             33
Using Method
<%! public String methodA() {
        return "Hello!";
    }
%>
<% out.println(methodA()); %>




                                 34
Practice




           35
Exercise
                    calculator.html

<form action=“calculator.jsp">
  Value1: <input name="value1">
  Value2: <input name="value2"><BR><BR>
  <input type="submit" name="cmd" value="Add">
  <input type="submit" name="cmd" value="Subtract">
  <input type="submit" name="cmd" value="Multiply">
  <input type="submit" name="cmd" value="Divide">
</form>




                                                      36
Exercise (cont.)
                           calculator.jsp

:
<% try {
      double value1 = Double.parseDouble(request.getParameter("value1"));
      double value2 = Double.parseDouble(request.getParameter("value2"));
      :
   } catch (NumberFormatException e) { %>
      Please enter valid numbers!!!
<% } %>




                                                                        37
Result




         38
JSP Standard Actions
    A JSP action directive provides an easy method
    to encapsulate common tasks. These typically
    create or act on objects, usually JavaBeans.
       <jsp:param>
       <jsp:include>
       <jsp:forward>
       <jsp:plugin>
       <jsp:useBean>
       <jsp:setProperty>
       <jsp:getProperty>


                                                      39
JSP Standard Actions
   <jsp:param>
      Is used to provide the tag/value pairs of
       information
      Included as sub-attributes of jsp:include,
       jsp:forward, and jsp:plugin actions
      The syntax is as follows:

    <jsp:param name = "pName" value = "pValue"/>

    <jsp:param name = "pName" value = "pValue">
    </jsp:param>
                                                    40
JSP Standard Actions
   <jsp:include>
     Provides a mechanism for including additional
     static and dynamic resources in the current JSP
     The syntax is as follows:

<jsp:include page = "urlSpec" flush = "true"/>


<jsp:include page = "urlSpec" flush = "true">
  <jsp:param .../>
</jsp:include>
                                                       41
Using <jsp:include> - An Example
<%-- header.jsp --%>
<h2> Company <%= request.getParameter("name")%></h2>
________________________________________________________________

<%-- infoCompany.jsp --%>
<jsp:include page="header.jsp" >
    <jsp:param name="name" value="ABC" />
</jsp:include>




                                                               42
JSP Standard Actions
   <jsp:forward>
     Enables the JSP engine to dispatch the current
     request to a static resource, a servlet, or to another
     JSP at run-time
     The syntax is as follows:

     <jsp:forward page = "relativeURLSpec" />


<jsp:forward page = "relativeURLSpec" >
  <jsp:param .../>
</jsp:forward>
                                                              43
Using <jsp:forward> - An Examples
<%-- date.jsp --%>
The current time is <%= new java.util.Date() %>
____________________________________________________
<%-- forwardDemo.jsp --%>
<jsp:forward page="date.jsp" />




                                                       44
JSP Standard Actions
   <jsp:plugin>
     Generates HTML that contains the appropriate client-
      browser dependent constructs, such as OBJECT or
      EMBED. This will prompt the download of the required
      Java plugin, and subsequent execution of the applet or
      bean.
     The syntax is as follows:

<jsp:plugin type="pluginType" code="classfilename">
   <jsp:params>
   <jsp:param …/>
   </jsp:params>
</jsp:plugin>
                                                               45
JSP Standard Actions
   <jsp:useBean>
     Associatesan instance of a pre-defined JavaBean with a
      given scope and ID
   <jsp:setProperty>
     Sets   the value of a bean’s property
   <jsp:getProperty>
     Accesses    the value of the specified property of a bean
      instance
     Converts it to a java.lang.String object
     Places it in the implicit out object
                                                                  46
Difference between a JavaBean
             and a Java class
    A bean is a Java class with the following
    additional characteristics:
 The class must be instantiable
 It must have a default constructor
 It must be serializable
 It must follow the JavaBeans design patterns
 It must follow the new Java 1.1 AWT
  delegation event model
                                                 47
Student.java
package myBeans;

public class Student implements java.io.Serializable {
    private String name;
    private String id;
                                              Property
    public void setName(String name) {
        this.name = name;                   setProperty()
    }
    public String getName() {
                                           getProperty()
        return name;
    }
    public void setId(String id) {
        this.id = id;
    }
    public String getId() {
        return id;
    }
}                                                           48
Using JSP Bean Tags

                  getProperty_Name()

                  setProperty_Name(value)



                     The JSP need not know the
                     inner structure of the bean
Bean



       The Black box approach
                                                   49
Using JSP Bean Tags
   JSP provides three basic bean tags:
     To find and use the bean – jsp:useBean
     To set one or more properties – jsp:setProperty
     To get a property – jsp:getProperty
   These are also known as actions and are
    specific tags that affect the following:
     the runtime behavior of the JSP
     the responses that are sent back to the client

                                                        50
jsp:useBean

   This is used to associate a JavaBean in JSP.

   It ensures that the object can be referenced from
    JSP, using an ID and scope
                                       The bean class
                                      must be available
   The syntax is as follows:         to the JSP engine

<jsp:useBean id="bean_name"
   scope=" page|request|session|application"
   class=" bean_class" >

                                                          51
Compare the Two
<%
 ShoppingCart cart = (ShoppingCart) session.getAttribute("cart");
 // If the user has no cart object as an attribute in Session scope
 // object, then create a new one. Otherwise, use the existing
 // instance.
 if (cart == null) {
     cart = new ShoppingCart();
     session.setAttribute("cart", cart);
 }
%>
                 versus

<jsp:useBean id="cart" class="cart.ShoppingCart" scope="session"/>
jsp:setProperty
   It sets the values of simple and indexed properties of
    a bean in various ways:
     At request time, using the parameters in the request object
     At request time, using the result of an evaluated expression
     From a specified string

   The syntax is as follows:
<jsp:setProperty name = "id" property = "*" />
<jsp:setProperty name = "id" property = "propertyName"
 param = "parameterName"/>
<jsp:setProperty name = "id" property = "propertyName"
 value = "propertyValue"/>
                                                                     53
Setting Bean Properties

 Properties can be set through an HTML form too
 The users can provide values through the form
 A JSP can be used to pass these values to a bean
  through the setProperty tags
 Form values can be passed like this:

    <jsp:setProperty   name="id" property="formParam" />




                                                           54
Compare the Two

 <jsp:setProperty name="bookDB" property="bookId"/>
 is same as
<%
  //Get the identifier of the book to display

 String bookId = request.getParameter("bookId");
 bookDB.setBookId(bookId);
     ...

%>
jsp:getProperty
   This action is complementary to the jsp:setProperty
    action
   It is used to access the properties of a bean
   It converts the retrieved value to a String
   The syntax is as follows:

    <jsp:getProperty name="id" property="propertyName" />




                                                            56
info.html and useBeanDemo.jsp
<!-- info.html -->
<form action=“useBeanDemo.jsp”>
  Name: <input name=“name”> Company: <input
  name=“company”>
  <input type=“submit” value=“Go!”>
</form>
________________________________________
<%-- useBeanDemo.jsp --%>
<jsp:useBean id="nameID" class="myBeans.Staff" />
<jsp:setProperty name="nameID" property="*" />
<jsp:getProperty name="nameID" property="name" />
<jsp:getProperty name="nameID" property="company" />


                                                       57
Result




         58
An Example
        The Bean – CounterBean.java
package myBeans;

import java.io.*;

public class CounterBean implements Serializable {
    private int count;
    public int getCount() {                Property
    return ++count;
    }                                     get Method
    public void setCount(int c) {
        count = c;
    }                                     set Method
}


                                                       59
An Example (cont.)

               The JSP that uses the bean
                                         Instantiate the
<HTML> . . .                              Counter bean
<jsp:useBean id="id_counter" scope="application"
 class="myBeans.CounterBean" />
<jsp:setProperty name="id_counter" property="count" />
<jsp:getProperty name="id_counter" property="count" />

. . . </HTML>




                                                           60
Scope of Beans
   By default, the objects created with jsp:useBean
    were bound to local variables in the _jspService
    method
   The beans are also stored in one of four different
    locations, depending on the value of the optional
    scope attribute of jsp:useBean




                                                         61
Scope of Beans (cont.)
   page
     This is the default value
     References to this object will only be released after the
      response is sent back to the client
   request
     The bean instance will be available as long as the request
      object is available
     References to this object will be released only after the
      request is processed completely


                                                                   62
Scope of Beans (cont.)
   session
     The instance will be available across a particular session
      between the browser of a particular machine and the Web
      server
     References to this object will be released only after the
      associated sessions end
   application
     The   instance will be available to all users and pages of the
      application
     It is released only when the run-time environment reclaims
      the ServletContext
                                                                       63
Scope of Beans (cont.)




                         64
An Example
      The Form – calculator1.html

<HTML> . . .

Enter any two numbers and click on the
<B>Calculate</B> Button.

<FORM ACTION = “useBean1.jsp">

Value1: <INPUT NAME = "value1">
Value2: <INPUT NAME = "value2">
<INPUT TYPE = "SUBMIT" VALUE = "Calculate">

. . . </HTML>

                                              65
An Example (cont.)
              The JSP – useBean1.jsp
<jsp:useBean id="calc" class="myBeans.CalcBean" />
<jsp:setProperty name="calc" property="*" />

<B> The sum of the two numbers is
<jsp:getProperty name="calc" property="sum" /></B>




                                                     66
An Example (cont.)
                The Bean – CalcBean.java
public class CalcBean implements java.io.Serializable {
  private int value1;
  private int value2;
  private int sum;

    public void setValue1(int num1) {
      value1 = num1;
    }

    public void setValue2(int num2) {
      value2 = num2;
    }

    public int getSum() {
      return value1 + value2;
    }                                                 67
}
Result




         68
JSP Standard Actions
   JSP actions have the following characteristics:
     These  tags are case-sensitive
     These are standard set of actions, supported by all
      containers
     Attribute values must be enclosed within quotes
     Tags must have a closing delimiter
     New actions can be built
     Existing actions can be extended
     Actions can be put into the output buffer
     Actions can access, modify, and create objects on the
      current server pages.
                                                              69
Comparison of Servlet and JSP

           Servlet                      JSP
   HTML code in              Java code in
    Java                       HTML
   Any form of Data          Structured Text
   Not easy to author        Very easy to author
   Underlying semantics      Code is compiled into a
                               servlet


                                                         70
Comparison of Servlet and JSP (cont.)




                                        71
Recommended Uses of JSP
 Application logic separated from Web content
  and embedded in components.
 Present dynamic portions of content, which is
  tailored to a specific use.
 Display repetitive portions of a Web site such
  as a header, a footer and a navigation bar.



                                                   72
Traditional MVC Architecture




                               73
MVC pattern (Model 2)
   Model 1 Architecture
     JavaBean (Model) to represent the business logic
     JSP (View) to handle all the request processing and provide the
      presentation

   Model 2 Architecture (Model-View-Controller)
     Often called the "MVC" or "Model 2" approach to JSP
     JavaBean (Model) to represent the business logic
     JSP (View) to provide the presentation
     Servlet (Controller) to handle all the request processing




                                                                        74
Model 2 Architecture as MVC




                              75
Best practice suggestion
   For complex pages, use both
     Servlet get request, validate and process
     forward() to JSP for dynamic generated response

     pass information as request attributes




                                                        76
A Typical Web Application
A flexible application with Java Servlet

                              Servlet




 Web Client


                                JSP


                                           77
Servlet : WelcomeName.java




     ::
String name == request.getParameter("username");
 String name    request.getParameter("username");
request.setAttribute("name", name);
 request.setAttribute("name", name);

RequestDispatcher rd == request.getRequestDispatcher("welcomeName.jsp");
 RequestDispatcher rd    request.getRequestDispatcher("welcomeName.jsp");
rd.forward(request, response);
 rd.forward(request, response);
     ::


                                                                            78
JSP : welcomeName.jsp

<img src="Duke.png">
 <img src="Duke.png">
<%= request.getAttribute("name") %>
 <%= request.getAttribute("name") %>




                                       79
Servlet/JSP Integration
   Joint servlet/JSP process:
     Original request is answered by a servlet
     Servlet processes request data, does database
     lookup,business logic, etc.
     Results are placed in beans
     Request is forwarded to a JSP page to format
     result
     Different JSP pages can be used to handle
     different types of presentation
                                                      80
Separate Business Logic From
         Presentation




                               81
Servlet : HelloName.java
    ::
String name = request.getParameter("username");
 String name = request.getParameter("username");
myBeans.Person obj = new myBeans.Person();
 myBeans.Person obj = new myBeans.Person();
obj.setName(name);
 obj.setName(name);
request.setAttribute("user", obj);
 request.setAttribute("user", obj);

RequestDispatcher rd =
 RequestDispatcher rd =
                 request.getRequestDispatcher(“helloName.jsp");
                  request.getRequestDispatcher(“helloName.jsp");
rd.forward(request, response);
 rd.forward(request, response);
     ::




                                                                   82
JSP : helloName.jsp

<img src="Duke.png">
 <img src="Duke.png">
<jsp:useBean id="user" class="myBeans.Person" scope="request" />
 <jsp:useBean id="user" class="myBeans.Person" scope="request" />
<jsp:getProperty name="user" property="name" />
 <jsp:getProperty name="user" property="name" />




                                                                    83
Java Bean : Person.java
package myBeans;
 package myBeans;

public class Person {
 public class Person {
    private String name;
     private String name;
    public void setName(String name) {
     public void setName(String name) {
        this.name = name;
         this.name = name;
    }}
    public String getName() {
     public String getName() {
        return name;
         return name;
    }}
}}




                                          84
Servlet, JSP & Java Bean




                           85
A Typical Web Application
JSP combined with Enterprise JavaBeans technology

          HTTP/HTML/XML

Browser


                      JSP



                                          EJBs
                              RMI/IIOP

                                                    86
Thank you

   thananum@gmail.com
www.facebook.com/imcinstitute
   www.imcinstitute.com



                                87

More Related Content

What's hot

Java EE Introduction
Java EE IntroductionJava EE Introduction
Java EE Introductionejlp12
 
Java Server Faces (JSF) - Basics
Java Server Faces (JSF) - BasicsJava Server Faces (JSF) - Basics
Java Server Faces (JSF) - BasicsBG Java EE Course
 
J2EE - JSP-Servlet- Container - Components
J2EE - JSP-Servlet- Container - ComponentsJ2EE - JSP-Servlet- Container - Components
J2EE - JSP-Servlet- Container - ComponentsKaml Sah
 
JSP - Java Server Page
JSP - Java Server PageJSP - Java Server Page
JSP - Java Server PageVipin Yadav
 
Java Web Programming [1/9] : Introduction to Web Application
Java Web Programming [1/9] : Introduction to Web ApplicationJava Web Programming [1/9] : Introduction to Web Application
Java Web Programming [1/9] : Introduction to Web ApplicationIMC Institute
 
Lap trinh web [Slide jsp]
Lap trinh web [Slide jsp]Lap trinh web [Slide jsp]
Lap trinh web [Slide jsp]Tri Nguyen
 
JAVA EE DEVELOPMENT (JSP and Servlets)
JAVA EE DEVELOPMENT (JSP and Servlets)JAVA EE DEVELOPMENT (JSP and Servlets)
JAVA EE DEVELOPMENT (JSP and Servlets)Talha Ocakçı
 
Lecture 1: Introduction to JEE
Lecture 1:  Introduction to JEELecture 1:  Introduction to JEE
Lecture 1: Introduction to JEEFahad Golra
 
Implicit objects advance Java
Implicit objects advance JavaImplicit objects advance Java
Implicit objects advance JavaDarshit Metaliya
 
Lecture 5 JSTL, custom tags, maven
Lecture 5   JSTL, custom tags, mavenLecture 5   JSTL, custom tags, maven
Lecture 5 JSTL, custom tags, mavenFahad Golra
 
Introduction to JSP pages
Introduction to JSP pagesIntroduction to JSP pages
Introduction to JSP pagesFulvio Corno
 
JAX-RS 2.0: RESTful Web Services
JAX-RS 2.0: RESTful Web ServicesJAX-RS 2.0: RESTful Web Services
JAX-RS 2.0: RESTful Web ServicesArun Gupta
 
Introduction to JSP
Introduction to JSPIntroduction to JSP
Introduction to JSPGeethu Mohan
 
Lecture 9 - Java Persistence, JPA 2
Lecture 9 - Java Persistence, JPA 2Lecture 9 - Java Persistence, JPA 2
Lecture 9 - Java Persistence, JPA 2Fahad Golra
 

What's hot (20)

J2EE jsp_01
J2EE jsp_01J2EE jsp_01
J2EE jsp_01
 
Java EE Introduction
Java EE IntroductionJava EE Introduction
Java EE Introduction
 
Java Server Faces (JSF) - Basics
Java Server Faces (JSF) - BasicsJava Server Faces (JSF) - Basics
Java Server Faces (JSF) - Basics
 
J2EE - JSP-Servlet- Container - Components
J2EE - JSP-Servlet- Container - ComponentsJ2EE - JSP-Servlet- Container - Components
J2EE - JSP-Servlet- Container - Components
 
JSP - Java Server Page
JSP - Java Server PageJSP - Java Server Page
JSP - Java Server Page
 
Java Web Programming [1/9] : Introduction to Web Application
Java Web Programming [1/9] : Introduction to Web ApplicationJava Web Programming [1/9] : Introduction to Web Application
Java Web Programming [1/9] : Introduction to Web Application
 
Lap trinh web [Slide jsp]
Lap trinh web [Slide jsp]Lap trinh web [Slide jsp]
Lap trinh web [Slide jsp]
 
Jsp sasidhar
Jsp sasidharJsp sasidhar
Jsp sasidhar
 
Java Server Pages
Java Server PagesJava Server Pages
Java Server Pages
 
Jdbc
JdbcJdbc
Jdbc
 
JAVA EE DEVELOPMENT (JSP and Servlets)
JAVA EE DEVELOPMENT (JSP and Servlets)JAVA EE DEVELOPMENT (JSP and Servlets)
JAVA EE DEVELOPMENT (JSP and Servlets)
 
Lecture 1: Introduction to JEE
Lecture 1:  Introduction to JEELecture 1:  Introduction to JEE
Lecture 1: Introduction to JEE
 
Jsp
JspJsp
Jsp
 
Implicit objects advance Java
Implicit objects advance JavaImplicit objects advance Java
Implicit objects advance Java
 
Jdbc api
Jdbc apiJdbc api
Jdbc api
 
Lecture 5 JSTL, custom tags, maven
Lecture 5   JSTL, custom tags, mavenLecture 5   JSTL, custom tags, maven
Lecture 5 JSTL, custom tags, maven
 
Introduction to JSP pages
Introduction to JSP pagesIntroduction to JSP pages
Introduction to JSP pages
 
JAX-RS 2.0: RESTful Web Services
JAX-RS 2.0: RESTful Web ServicesJAX-RS 2.0: RESTful Web Services
JAX-RS 2.0: RESTful Web Services
 
Introduction to JSP
Introduction to JSPIntroduction to JSP
Introduction to JSP
 
Lecture 9 - Java Persistence, JPA 2
Lecture 9 - Java Persistence, JPA 2Lecture 9 - Java Persistence, JPA 2
Lecture 9 - Java Persistence, JPA 2
 

Viewers also liked (20)

Jsp
JspJsp
Jsp
 
Ordbms
OrdbmsOrdbms
Ordbms
 
Software Quality Assurance
Software Quality AssuranceSoftware Quality Assurance
Software Quality Assurance
 
Verification and Validation in Software Engineering SE19
Verification and Validation in Software Engineering SE19Verification and Validation in Software Engineering SE19
Verification and Validation in Software Engineering SE19
 
Hibernate Developer Reference
Hibernate Developer ReferenceHibernate Developer Reference
Hibernate Developer Reference
 
JDBC Java Database Connectivity
JDBC Java Database ConnectivityJDBC Java Database Connectivity
JDBC Java Database Connectivity
 
Java Server Pages
Java Server PagesJava Server Pages
Java Server Pages
 
JDBC: java DataBase connectivity
JDBC: java DataBase connectivityJDBC: java DataBase connectivity
JDBC: java DataBase connectivity
 
Java Servlets
Java ServletsJava Servlets
Java Servlets
 
Black box & white-box testing technique
Black box & white-box testing techniqueBlack box & white-box testing technique
Black box & white-box testing technique
 
Black & White Box testing
Black & White Box testingBlack & White Box testing
Black & White Box testing
 
Software quality assurance
Software quality assuranceSoftware quality assurance
Software quality assurance
 
Jdbc Ppt
Jdbc PptJdbc Ppt
Jdbc Ppt
 
Dynamic Testing
Dynamic TestingDynamic Testing
Dynamic Testing
 
Software Testing Fundamentals
Software Testing FundamentalsSoftware Testing Fundamentals
Software Testing Fundamentals
 
Static testing vs dynamic testing
Static testing vs dynamic testingStatic testing vs dynamic testing
Static testing vs dynamic testing
 
Software testing ppt
Software testing pptSoftware testing ppt
Software testing ppt
 
Servlet and JSP Lifecycle
Servlet and JSP LifecycleServlet and JSP Lifecycle
Servlet and JSP Lifecycle
 
Servlet/JSP course chapter 1: Introduction to servlets
Servlet/JSP course chapter 1: Introduction to servletsServlet/JSP course chapter 1: Introduction to servlets
Servlet/JSP course chapter 1: Introduction to servlets
 
4. jsp
4. jsp4. jsp
4. jsp
 

Similar to Java Web Programming [4/9] : JSP Basic

Similar to Java Web Programming [4/9] : JSP Basic (20)

Jsp in Servlet by Rj
Jsp in Servlet by RjJsp in Servlet by Rj
Jsp in Servlet by Rj
 
Introduction to JSP.pptx
Introduction to JSP.pptxIntroduction to JSP.pptx
Introduction to JSP.pptx
 
Jsp
JspJsp
Jsp
 
JSP Technology I
JSP Technology IJSP Technology I
JSP Technology I
 
Introduction to JSP
Introduction to JSPIntroduction to JSP
Introduction to JSP
 
JSP.pptx
JSP.pptxJSP.pptx
JSP.pptx
 
Internet and Web Technology (CLASS-14) [JSP] | NIC/NIELIT Web Technology
Internet and Web Technology (CLASS-14) [JSP] | NIC/NIELIT Web Technology Internet and Web Technology (CLASS-14) [JSP] | NIC/NIELIT Web Technology
Internet and Web Technology (CLASS-14) [JSP] | NIC/NIELIT Web Technology
 
Java server pages
Java server pagesJava server pages
Java server pages
 
Jsp Introduction Tutorial
Jsp Introduction TutorialJsp Introduction Tutorial
Jsp Introduction Tutorial
 
Jsp interview questions by java training center
Jsp interview questions by java training centerJsp interview questions by java training center
Jsp interview questions by java training center
 
JSP Directives
JSP DirectivesJSP Directives
JSP Directives
 
Chap4 4 2
Chap4 4 2Chap4 4 2
Chap4 4 2
 
DataBase Connectivity
DataBase ConnectivityDataBase Connectivity
DataBase Connectivity
 
JSP overview
JSP overviewJSP overview
JSP overview
 
anatomy of a jsp page & jsp syntax.pptx
anatomy of a jsp page & jsp syntax.pptxanatomy of a jsp page & jsp syntax.pptx
anatomy of a jsp page & jsp syntax.pptx
 
JSP- JAVA SERVER PAGES
JSP- JAVA SERVER PAGESJSP- JAVA SERVER PAGES
JSP- JAVA SERVER PAGES
 
Java server pages
Java server pagesJava server pages
Java server pages
 
3.jsp tutorial
3.jsp tutorial3.jsp tutorial
3.jsp tutorial
 
Spatial approximate string search Doc
Spatial approximate string search DocSpatial approximate string search Doc
Spatial approximate string search Doc
 
Java Server Pages
Java Server PagesJava Server Pages
Java Server Pages
 

More from IMC Institute

นิตยสาร Digital Trends ฉบับที่ 14
นิตยสาร Digital Trends ฉบับที่ 14นิตยสาร Digital Trends ฉบับที่ 14
นิตยสาร Digital Trends ฉบับที่ 14IMC Institute
 
Digital trends Vol 4 No. 13 Sep-Dec 2019
Digital trends Vol 4 No. 13  Sep-Dec 2019Digital trends Vol 4 No. 13  Sep-Dec 2019
Digital trends Vol 4 No. 13 Sep-Dec 2019IMC Institute
 
บทความ The evolution of AI
บทความ The evolution of AIบทความ The evolution of AI
บทความ The evolution of AIIMC Institute
 
IT Trends eMagazine Vol 4. No.12
IT Trends eMagazine  Vol 4. No.12IT Trends eMagazine  Vol 4. No.12
IT Trends eMagazine Vol 4. No.12IMC Institute
 
เพราะเหตุใด Digitization ไม่ตอบโจทย์ Digital Transformation
เพราะเหตุใด Digitization ไม่ตอบโจทย์ Digital Transformationเพราะเหตุใด Digitization ไม่ตอบโจทย์ Digital Transformation
เพราะเหตุใด Digitization ไม่ตอบโจทย์ Digital TransformationIMC Institute
 
IT Trends 2019: Putting Digital Transformation to Work
IT Trends 2019: Putting Digital Transformation to WorkIT Trends 2019: Putting Digital Transformation to Work
IT Trends 2019: Putting Digital Transformation to WorkIMC Institute
 
มูลค่าตลาดดิจิทัลไทย 3 อุตสาหกรรม
มูลค่าตลาดดิจิทัลไทย 3 อุตสาหกรรมมูลค่าตลาดดิจิทัลไทย 3 อุตสาหกรรม
มูลค่าตลาดดิจิทัลไทย 3 อุตสาหกรรมIMC Institute
 
IT Trends eMagazine Vol 4. No.11
IT Trends eMagazine  Vol 4. No.11IT Trends eMagazine  Vol 4. No.11
IT Trends eMagazine Vol 4. No.11IMC Institute
 
แนวทางการทำ Digital transformation
แนวทางการทำ Digital transformationแนวทางการทำ Digital transformation
แนวทางการทำ Digital transformationIMC Institute
 
บทความ The New Silicon Valley
บทความ The New Silicon Valleyบทความ The New Silicon Valley
บทความ The New Silicon ValleyIMC Institute
 
นิตยสาร IT Trends ของ IMC Institute ฉบับที่ 10
นิตยสาร IT Trends ของ  IMC Institute  ฉบับที่ 10นิตยสาร IT Trends ของ  IMC Institute  ฉบับที่ 10
นิตยสาร IT Trends ของ IMC Institute ฉบับที่ 10IMC Institute
 
แนวทางการทำ Digital transformation
แนวทางการทำ Digital transformationแนวทางการทำ Digital transformation
แนวทางการทำ Digital transformationIMC Institute
 
The Power of Big Data for a new economy (Sample)
The Power of Big Data for a new economy (Sample)The Power of Big Data for a new economy (Sample)
The Power of Big Data for a new economy (Sample)IMC Institute
 
บทความ Robotics แนวโน้มใหม่สู่บริการเฉพาะทาง
บทความ Robotics แนวโน้มใหม่สู่บริการเฉพาะทาง บทความ Robotics แนวโน้มใหม่สู่บริการเฉพาะทาง
บทความ Robotics แนวโน้มใหม่สู่บริการเฉพาะทาง IMC Institute
 
IT Trends eMagazine Vol 3. No.9
IT Trends eMagazine  Vol 3. No.9 IT Trends eMagazine  Vol 3. No.9
IT Trends eMagazine Vol 3. No.9 IMC Institute
 
Thailand software & software market survey 2016
Thailand software & software market survey 2016Thailand software & software market survey 2016
Thailand software & software market survey 2016IMC Institute
 
Developing Business Blockchain Applications on Hyperledger
Developing Business  Blockchain Applications on Hyperledger Developing Business  Blockchain Applications on Hyperledger
Developing Business Blockchain Applications on Hyperledger IMC Institute
 
Digital transformation @thanachart.org
Digital transformation @thanachart.orgDigital transformation @thanachart.org
Digital transformation @thanachart.orgIMC Institute
 
บทความ Big Data จากบล็อก thanachart.org
บทความ Big Data จากบล็อก thanachart.orgบทความ Big Data จากบล็อก thanachart.org
บทความ Big Data จากบล็อก thanachart.orgIMC Institute
 
กลยุทธ์ 5 ด้านกับการทำ Digital Transformation
กลยุทธ์ 5 ด้านกับการทำ Digital Transformationกลยุทธ์ 5 ด้านกับการทำ Digital Transformation
กลยุทธ์ 5 ด้านกับการทำ Digital TransformationIMC Institute
 

More from IMC Institute (20)

นิตยสาร Digital Trends ฉบับที่ 14
นิตยสาร Digital Trends ฉบับที่ 14นิตยสาร Digital Trends ฉบับที่ 14
นิตยสาร Digital Trends ฉบับที่ 14
 
Digital trends Vol 4 No. 13 Sep-Dec 2019
Digital trends Vol 4 No. 13  Sep-Dec 2019Digital trends Vol 4 No. 13  Sep-Dec 2019
Digital trends Vol 4 No. 13 Sep-Dec 2019
 
บทความ The evolution of AI
บทความ The evolution of AIบทความ The evolution of AI
บทความ The evolution of AI
 
IT Trends eMagazine Vol 4. No.12
IT Trends eMagazine  Vol 4. No.12IT Trends eMagazine  Vol 4. No.12
IT Trends eMagazine Vol 4. No.12
 
เพราะเหตุใด Digitization ไม่ตอบโจทย์ Digital Transformation
เพราะเหตุใด Digitization ไม่ตอบโจทย์ Digital Transformationเพราะเหตุใด Digitization ไม่ตอบโจทย์ Digital Transformation
เพราะเหตุใด Digitization ไม่ตอบโจทย์ Digital Transformation
 
IT Trends 2019: Putting Digital Transformation to Work
IT Trends 2019: Putting Digital Transformation to WorkIT Trends 2019: Putting Digital Transformation to Work
IT Trends 2019: Putting Digital Transformation to Work
 
มูลค่าตลาดดิจิทัลไทย 3 อุตสาหกรรม
มูลค่าตลาดดิจิทัลไทย 3 อุตสาหกรรมมูลค่าตลาดดิจิทัลไทย 3 อุตสาหกรรม
มูลค่าตลาดดิจิทัลไทย 3 อุตสาหกรรม
 
IT Trends eMagazine Vol 4. No.11
IT Trends eMagazine  Vol 4. No.11IT Trends eMagazine  Vol 4. No.11
IT Trends eMagazine Vol 4. No.11
 
แนวทางการทำ Digital transformation
แนวทางการทำ Digital transformationแนวทางการทำ Digital transformation
แนวทางการทำ Digital transformation
 
บทความ The New Silicon Valley
บทความ The New Silicon Valleyบทความ The New Silicon Valley
บทความ The New Silicon Valley
 
นิตยสาร IT Trends ของ IMC Institute ฉบับที่ 10
นิตยสาร IT Trends ของ  IMC Institute  ฉบับที่ 10นิตยสาร IT Trends ของ  IMC Institute  ฉบับที่ 10
นิตยสาร IT Trends ของ IMC Institute ฉบับที่ 10
 
แนวทางการทำ Digital transformation
แนวทางการทำ Digital transformationแนวทางการทำ Digital transformation
แนวทางการทำ Digital transformation
 
The Power of Big Data for a new economy (Sample)
The Power of Big Data for a new economy (Sample)The Power of Big Data for a new economy (Sample)
The Power of Big Data for a new economy (Sample)
 
บทความ Robotics แนวโน้มใหม่สู่บริการเฉพาะทาง
บทความ Robotics แนวโน้มใหม่สู่บริการเฉพาะทาง บทความ Robotics แนวโน้มใหม่สู่บริการเฉพาะทาง
บทความ Robotics แนวโน้มใหม่สู่บริการเฉพาะทาง
 
IT Trends eMagazine Vol 3. No.9
IT Trends eMagazine  Vol 3. No.9 IT Trends eMagazine  Vol 3. No.9
IT Trends eMagazine Vol 3. No.9
 
Thailand software & software market survey 2016
Thailand software & software market survey 2016Thailand software & software market survey 2016
Thailand software & software market survey 2016
 
Developing Business Blockchain Applications on Hyperledger
Developing Business  Blockchain Applications on Hyperledger Developing Business  Blockchain Applications on Hyperledger
Developing Business Blockchain Applications on Hyperledger
 
Digital transformation @thanachart.org
Digital transformation @thanachart.orgDigital transformation @thanachart.org
Digital transformation @thanachart.org
 
บทความ Big Data จากบล็อก thanachart.org
บทความ Big Data จากบล็อก thanachart.orgบทความ Big Data จากบล็อก thanachart.org
บทความ Big Data จากบล็อก thanachart.org
 
กลยุทธ์ 5 ด้านกับการทำ Digital Transformation
กลยุทธ์ 5 ด้านกับการทำ Digital Transformationกลยุทธ์ 5 ด้านกับการทำ Digital Transformation
กลยุทธ์ 5 ด้านกับการทำ Digital Transformation
 

Recently uploaded

The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...
The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...
The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...Wes McKinney
 
So einfach geht modernes Roaming fuer Notes und Nomad.pdf
So einfach geht modernes Roaming fuer Notes und Nomad.pdfSo einfach geht modernes Roaming fuer Notes und Nomad.pdf
So einfach geht modernes Roaming fuer Notes und Nomad.pdfpanagenda
 
How to Effectively Monitor SD-WAN and SASE Environments with ThousandEyes
How to Effectively Monitor SD-WAN and SASE Environments with ThousandEyesHow to Effectively Monitor SD-WAN and SASE Environments with ThousandEyes
How to Effectively Monitor SD-WAN and SASE Environments with ThousandEyesThousandEyes
 
The State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptxThe State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptxLoriGlavin3
 
UiPath Community: Communication Mining from Zero to Hero
UiPath Community: Communication Mining from Zero to HeroUiPath Community: Communication Mining from Zero to Hero
UiPath Community: Communication Mining from Zero to HeroUiPathCommunity
 
A Journey Into the Emotions of Software Developers
A Journey Into the Emotions of Software DevelopersA Journey Into the Emotions of Software Developers
A Journey Into the Emotions of Software DevelopersNicole Novielli
 
[Webinar] SpiraTest - Setting New Standards in Quality Assurance
[Webinar] SpiraTest - Setting New Standards in Quality Assurance[Webinar] SpiraTest - Setting New Standards in Quality Assurance
[Webinar] SpiraTest - Setting New Standards in Quality AssuranceInflectra
 
TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024Lonnie McRorey
 
Connecting the Dots for Information Discovery.pdf
Connecting the Dots for Information Discovery.pdfConnecting the Dots for Information Discovery.pdf
Connecting the Dots for Information Discovery.pdfNeo4j
 
Data governance with Unity Catalog Presentation
Data governance with Unity Catalog PresentationData governance with Unity Catalog Presentation
Data governance with Unity Catalog PresentationKnoldus Inc.
 
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxMerck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxLoriGlavin3
 
What is DBT - The Ultimate Data Build Tool.pdf
What is DBT - The Ultimate Data Build Tool.pdfWhat is DBT - The Ultimate Data Build Tool.pdf
What is DBT - The Ultimate Data Build Tool.pdfMounikaPolabathina
 
From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .Alan Dix
 
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024BookNet Canada
 
Manual 508 Accessibility Compliance Audit
Manual 508 Accessibility Compliance AuditManual 508 Accessibility Compliance Audit
Manual 508 Accessibility Compliance AuditSkynet Technologies
 
Digital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptxDigital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptxLoriGlavin3
 
Sample pptx for embedding into website for demo
Sample pptx for embedding into website for demoSample pptx for embedding into website for demo
Sample pptx for embedding into website for demoHarshalMandlekar2
 
Genislab builds better products and faster go-to-market with Lean project man...
Genislab builds better products and faster go-to-market with Lean project man...Genislab builds better products and faster go-to-market with Lean project man...
Genislab builds better products and faster go-to-market with Lean project man...Farhan Tariq
 
2024 April Patch Tuesday
2024 April Patch Tuesday2024 April Patch Tuesday
2024 April Patch TuesdayIvanti
 
Generative Artificial Intelligence: How generative AI works.pdf
Generative Artificial Intelligence: How generative AI works.pdfGenerative Artificial Intelligence: How generative AI works.pdf
Generative Artificial Intelligence: How generative AI works.pdfIngrid Airi González
 

Recently uploaded (20)

The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...
The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...
The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...
 
So einfach geht modernes Roaming fuer Notes und Nomad.pdf
So einfach geht modernes Roaming fuer Notes und Nomad.pdfSo einfach geht modernes Roaming fuer Notes und Nomad.pdf
So einfach geht modernes Roaming fuer Notes und Nomad.pdf
 
How to Effectively Monitor SD-WAN and SASE Environments with ThousandEyes
How to Effectively Monitor SD-WAN and SASE Environments with ThousandEyesHow to Effectively Monitor SD-WAN and SASE Environments with ThousandEyes
How to Effectively Monitor SD-WAN and SASE Environments with ThousandEyes
 
The State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptxThe State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptx
 
UiPath Community: Communication Mining from Zero to Hero
UiPath Community: Communication Mining from Zero to HeroUiPath Community: Communication Mining from Zero to Hero
UiPath Community: Communication Mining from Zero to Hero
 
A Journey Into the Emotions of Software Developers
A Journey Into the Emotions of Software DevelopersA Journey Into the Emotions of Software Developers
A Journey Into the Emotions of Software Developers
 
[Webinar] SpiraTest - Setting New Standards in Quality Assurance
[Webinar] SpiraTest - Setting New Standards in Quality Assurance[Webinar] SpiraTest - Setting New Standards in Quality Assurance
[Webinar] SpiraTest - Setting New Standards in Quality Assurance
 
TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024
 
Connecting the Dots for Information Discovery.pdf
Connecting the Dots for Information Discovery.pdfConnecting the Dots for Information Discovery.pdf
Connecting the Dots for Information Discovery.pdf
 
Data governance with Unity Catalog Presentation
Data governance with Unity Catalog PresentationData governance with Unity Catalog Presentation
Data governance with Unity Catalog Presentation
 
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxMerck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
 
What is DBT - The Ultimate Data Build Tool.pdf
What is DBT - The Ultimate Data Build Tool.pdfWhat is DBT - The Ultimate Data Build Tool.pdf
What is DBT - The Ultimate Data Build Tool.pdf
 
From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .
 
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
 
Manual 508 Accessibility Compliance Audit
Manual 508 Accessibility Compliance AuditManual 508 Accessibility Compliance Audit
Manual 508 Accessibility Compliance Audit
 
Digital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptxDigital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptx
 
Sample pptx for embedding into website for demo
Sample pptx for embedding into website for demoSample pptx for embedding into website for demo
Sample pptx for embedding into website for demo
 
Genislab builds better products and faster go-to-market with Lean project man...
Genislab builds better products and faster go-to-market with Lean project man...Genislab builds better products and faster go-to-market with Lean project man...
Genislab builds better products and faster go-to-market with Lean project man...
 
2024 April Patch Tuesday
2024 April Patch Tuesday2024 April Patch Tuesday
2024 April Patch Tuesday
 
Generative Artificial Intelligence: How generative AI works.pdf
Generative Artificial Intelligence: How generative AI works.pdfGenerative Artificial Intelligence: How generative AI works.pdf
Generative Artificial Intelligence: How generative AI works.pdf
 

Java Web Programming [4/9] : JSP Basic

  • 1. Module 4: JSP Basics Thanisa Kruawaisayawan Thanachart Numnonda www.imcinstitute.com 1
  • 2. Objectives  What is JSP?  What are the Advantages of JSP?  Elements of a JSP files and tags  JSP and Java Beans  Link Servlet and JSP 2
  • 3. What is JSP?  A way to create dynamic web pages  A text-based documents capable of returning dynamic content to a client browser  Server side processing  Based on Java Technology  Large library base  Platform independence  Contains HTML, XML, programming code, and JSP tags (HTML and XML tags) allowing access to components such as JavaBeans  Separates the graphical design from the dynamic content 3
  • 4. Compiled into a Servlet myJSP.jsp myJSP_jsp.java myJSP_jsp.class jspInit() _jspService() jspDestroy() 4
  • 5. The JSP Life Cycle  The life cycle of a JSP can be split into approximately four phases:  Translation  The JSP engine will translate the JSP into its page implementation servlet and compile it into a class file  Initialization  The JSP engine will need to load the generated class file and create an instance of the servlet  Servicing  The methods jspInit() and _jspService() will be called  Destruction  The method jspDestroy() will be called 5
  • 6. How Do JavaServer Pages Work? HTTP WEB JSP Client SERVER ENGINE Database JSPs are processed here JSP Files 6
  • 7. JSP Page Translation Procedure 7
  • 8. What are the Advantages of JSP?  Content and display logic are separated.  Simplify development with JSP, JavaBeans and custom tags.  Supports software reuse through the use of components.  Recompile automatically when changes are made to the source file.  Easier to author.  Platform-independent 8
  • 10. What does a JSP look like?  Three main JSP constructs:  Directives  Allows one to control structure of the servlet  Scripting Elements  Used to include Java code  Actions  Specific tags that affect the runtime behavior of the JSPs 10
  • 11. Fixed Template An Example data <HTML> <HEAD><TITLE>MyFirstProgram.jsp</TITLE></HEAD> <BODY> JSP <!-- MyFirstProgram.JSP --> Directive <%@ page import = "java.util.Date" %> JSP Scripting <% out.println("Hello there!"); %><BR> JSP Action <jsp:useBean id="name" scope="page" class="myBean.SimpleBean" /> </BODY> </HTML> 11
  • 12. Directives  JSP page have the following three types of directives:  page  include  taglib  All three directive types must be declared between < %@ and %> directive delimiters and take the following form: <%@ directive {attribute="value"}* %> 12
  • 13. The page Directive  The page directive is a JSP tag that you will use in almost every JSP source file.  The page directive gives instructions to the JSP container that apply to the entire JSP source file.  page might specify the scripting language used in the JSP source file, packages the source file would import, or the error page called if an error or exception occurs.  You can use the page directive anywhere in the JSP file, but it’s good coding style to place it at the top of the file. 13
  • 14. Attributes of The page Directive  language  Currently, JSP 2.0 only supports a value of "Java"  extends  Java class that will form the superclass of the JSP page’s servlet.  import  Indicates the classes available for use within the scripting environment  The default import list is as follows:  javax.servlet.jsp.* and  javax.servlet.http.*  session  Indicates that the page requires an HttpSession  The default value is "true" 14
  • 15. Attributes of The page Directive (cont.)  buffer  Specifies the buffering model for JspWriter used to handle the response  The default value isn’t less than 8 KB.  autoFlush  Indicate whether the output buffer should be flushed automatically when full  The default value is "true"  isThreadSafe  Indicates the threading model to be used by the JSP  The default value is "true"  info  Can be used to provide any arbitrary string  Returned via a call to the page servlet’s getServletInfo() method 15
  • 16. Attributes of The page Directive (cont.)  isErrorPage  Indicates whether or not the current JSP is intended to be an error page  The default value is "false"  errorPage  Defines the URL that any throwable objects are forwarded for error processing  contentType  Defines the character encoding for the JSP page and MIME type of the response  The default value for the type is "text/html" and for the charset it’s "ISO-8859-1" 16
  • 17. Attributes of The page Directive (cont.)  pageEncoding  Defines the character encoding for the JSP page  The default value is "ISO-8859-1"  isELignored  Defines whether the EL (Expression Language) expressions are evaluated for the JSP page  The default value is "false" 17
  • 18. Examples of The page Directive <%@ page language="java" %> <%@ page language="java" %> <%@ page import="java.util.*, java.text.*" %> <%@ page import="java.util.*, java.text.*" %> <%@ page extends="Servlet1" %> <%@ page extends="Servlet1" %> <%@ page session="true" %> <%@ page session="true" %> <%@ page buffer="16kb" %> <%@ page buffer="16kb" %> <%@ page autoFlush="true" %> <%@ page autoFlush="true" %> <%@ page isThreadSafe="false" %> <%@ page isThreadSafe="false" %> <%@ page info="First JSP" %> <%@ page info="First JSP" %> <%@ page isErrorPage="false" %> <%@ page isErrorPage="false" %> <%@ page errorPage="ErrorPage.jsp" %> <%@ page errorPage="ErrorPage.jsp" %> <%@ page contentType="text/html" %> <%@ page contentType="text/html" %> <%@ page pageEncoding="ISO-8859-1" %> <%@ page pageEncoding="ISO-8859-1" %> <%@ page isELIgnored="false" %> <%@ page isELIgnored="false" %> 18
  • 19. The include Directive  The include directive inserts the contents of another file in the main JSP file, where the directive is located .  It’s useful for including copyright information, scripting language files, or anything you might want t o reuse in other applications.  The included file does not contain <html> or <body> tags, because these tags would conflict with the same tags in the calling JSP file. 19
  • 20. Example <!-- dukeBanner.html --> <img src="Duke.png"> ____________________________________________________ <%-- welcome.jsp --%> <%@ include file=“dukeBanner.html" %> 20
  • 21. Scripting Elements  Comments  Declarations  Scriptlets  Expressions 21
  • 22. Comments  JSP comments may be declared inside a JSP as follows: <%-- This is JSP comment. --%>  HTML comments <!-- This is HTML comment. -->  They are the same? 22
  • 23. Declarations  Declarations are the definition of class-level variables and methods that are used in a JSP.  The general syntax is as follows: <%! Declaration; %>  Example:  <%! private int count; %>  <%! Date now = new Date(); %>  <%! private int sum(int a, int b) { …return a+b; } %> 23
  • 24. JSP Scripting Elements Points to remember about declarations:  Declarations do not produce any printable results.  Variables are initialized when the JSP is initialized.  Such variables are available to other declarations, expressions, and scriptlets.  Variables created through declarations become instance variables.  Simultaneous users of the JSP share the same instance of the variable.  Class variables and methods can be declared in a declaration block. 24
  • 25. Scriptlets  Scriptlets are small blocks of source code contained within the <% and %>  The general syntax is as follows: <% scriptlet_source; %>  Example <% out.println(++count); %> 25
  • 26. Example <%! int count; %> <% out.println(++count); %> They are the same? <% int count = 0; %> <% out.println(++count); %> 26
  • 27. Implicit Objects  Server-side objects are defined by the JSP container  They are always available in a JSP, without being declared  These objects determine:  how to accept the request from the browser  how to send the response from the server  how session tracking can be done 27
  • 28. Implicit Objects (cont.) Objects class scope request javax.servlet.http.HttpServletRequest request response javax.servlet.http.HttpServletResponse page session javax.servlet.http.HttpSession session application javax.servlet.ServletContext application out javax.servlet.jsp.JspWriter page PageContext javax.servlet.jsp.PageContext page config javax.servlet.ServletConfig page page java.lang.Object page exception java.lang.Throwable application 28
  • 29. Expressions  Evaluate a regular Java expression and return a String or be convertible to a String result  The general syntax is as follows: <%= expression %>  Example <%= ++count %>  JSP expressions don’t require a closing semicolon. 29
  • 30. A Simple Web Application 30
  • 31. Conditional Statements <%! int count; %> This page has been accessed <%= ++count %> time(s). <BR> <% if (count == 1) { %> Welcome, you are the first visitor to our site.<BR> <% } else { %> You are not the first visitor to our site.<BR> <% } %> Please do visit us again. Thank you! 31
  • 32. Iterative Statements (For) <% for (int i=0; i<5; i++) { %> Welcome to our site! <BR> <% } %> 32
  • 33. Iterative Statements (While) <% java.util.Enumeration enum1 = request.getHeaderNames(); %> <% while (enum1.hasMoreElements()) { %> <%= enum1.nextElement() %> <BR> <% } %> 33
  • 34. Using Method <%! public String methodA() { return "Hello!"; } %> <% out.println(methodA()); %> 34
  • 35. Practice 35
  • 36. Exercise calculator.html <form action=“calculator.jsp"> Value1: <input name="value1"> Value2: <input name="value2"><BR><BR> <input type="submit" name="cmd" value="Add"> <input type="submit" name="cmd" value="Subtract"> <input type="submit" name="cmd" value="Multiply"> <input type="submit" name="cmd" value="Divide"> </form> 36
  • 37. Exercise (cont.) calculator.jsp : <% try { double value1 = Double.parseDouble(request.getParameter("value1")); double value2 = Double.parseDouble(request.getParameter("value2")); : } catch (NumberFormatException e) { %> Please enter valid numbers!!! <% } %> 37
  • 38. Result 38
  • 39. JSP Standard Actions  A JSP action directive provides an easy method to encapsulate common tasks. These typically create or act on objects, usually JavaBeans.  <jsp:param>  <jsp:include>  <jsp:forward>  <jsp:plugin>  <jsp:useBean>  <jsp:setProperty>  <jsp:getProperty> 39
  • 40. JSP Standard Actions  <jsp:param>  Is used to provide the tag/value pairs of information  Included as sub-attributes of jsp:include, jsp:forward, and jsp:plugin actions  The syntax is as follows: <jsp:param name = "pName" value = "pValue"/> <jsp:param name = "pName" value = "pValue"> </jsp:param> 40
  • 41. JSP Standard Actions  <jsp:include>  Provides a mechanism for including additional static and dynamic resources in the current JSP  The syntax is as follows: <jsp:include page = "urlSpec" flush = "true"/> <jsp:include page = "urlSpec" flush = "true"> <jsp:param .../> </jsp:include> 41
  • 42. Using <jsp:include> - An Example <%-- header.jsp --%> <h2> Company <%= request.getParameter("name")%></h2> ________________________________________________________________ <%-- infoCompany.jsp --%> <jsp:include page="header.jsp" > <jsp:param name="name" value="ABC" /> </jsp:include> 42
  • 43. JSP Standard Actions  <jsp:forward>  Enables the JSP engine to dispatch the current request to a static resource, a servlet, or to another JSP at run-time  The syntax is as follows: <jsp:forward page = "relativeURLSpec" /> <jsp:forward page = "relativeURLSpec" > <jsp:param .../> </jsp:forward> 43
  • 44. Using <jsp:forward> - An Examples <%-- date.jsp --%> The current time is <%= new java.util.Date() %> ____________________________________________________ <%-- forwardDemo.jsp --%> <jsp:forward page="date.jsp" /> 44
  • 45. JSP Standard Actions  <jsp:plugin>  Generates HTML that contains the appropriate client- browser dependent constructs, such as OBJECT or EMBED. This will prompt the download of the required Java plugin, and subsequent execution of the applet or bean.  The syntax is as follows: <jsp:plugin type="pluginType" code="classfilename"> <jsp:params> <jsp:param …/> </jsp:params> </jsp:plugin> 45
  • 46. JSP Standard Actions  <jsp:useBean>  Associatesan instance of a pre-defined JavaBean with a given scope and ID  <jsp:setProperty>  Sets the value of a bean’s property  <jsp:getProperty>  Accesses the value of the specified property of a bean instance  Converts it to a java.lang.String object  Places it in the implicit out object 46
  • 47. Difference between a JavaBean and a Java class A bean is a Java class with the following additional characteristics:  The class must be instantiable  It must have a default constructor  It must be serializable  It must follow the JavaBeans design patterns  It must follow the new Java 1.1 AWT delegation event model 47
  • 48. Student.java package myBeans; public class Student implements java.io.Serializable { private String name; private String id; Property public void setName(String name) { this.name = name; setProperty() } public String getName() { getProperty() return name; } public void setId(String id) { this.id = id; } public String getId() { return id; } } 48
  • 49. Using JSP Bean Tags getProperty_Name() setProperty_Name(value) The JSP need not know the inner structure of the bean Bean The Black box approach 49
  • 50. Using JSP Bean Tags  JSP provides three basic bean tags:  To find and use the bean – jsp:useBean  To set one or more properties – jsp:setProperty  To get a property – jsp:getProperty  These are also known as actions and are specific tags that affect the following:  the runtime behavior of the JSP  the responses that are sent back to the client 50
  • 51. jsp:useBean  This is used to associate a JavaBean in JSP.  It ensures that the object can be referenced from JSP, using an ID and scope The bean class must be available  The syntax is as follows: to the JSP engine <jsp:useBean id="bean_name" scope=" page|request|session|application" class=" bean_class" > 51
  • 52. Compare the Two <% ShoppingCart cart = (ShoppingCart) session.getAttribute("cart"); // If the user has no cart object as an attribute in Session scope // object, then create a new one. Otherwise, use the existing // instance. if (cart == null) { cart = new ShoppingCart(); session.setAttribute("cart", cart); } %> versus <jsp:useBean id="cart" class="cart.ShoppingCart" scope="session"/>
  • 53. jsp:setProperty  It sets the values of simple and indexed properties of a bean in various ways:  At request time, using the parameters in the request object  At request time, using the result of an evaluated expression  From a specified string  The syntax is as follows: <jsp:setProperty name = "id" property = "*" /> <jsp:setProperty name = "id" property = "propertyName" param = "parameterName"/> <jsp:setProperty name = "id" property = "propertyName" value = "propertyValue"/> 53
  • 54. Setting Bean Properties  Properties can be set through an HTML form too  The users can provide values through the form  A JSP can be used to pass these values to a bean through the setProperty tags  Form values can be passed like this: <jsp:setProperty name="id" property="formParam" /> 54
  • 55. Compare the Two <jsp:setProperty name="bookDB" property="bookId"/> is same as <% //Get the identifier of the book to display String bookId = request.getParameter("bookId"); bookDB.setBookId(bookId); ... %>
  • 56. jsp:getProperty  This action is complementary to the jsp:setProperty action  It is used to access the properties of a bean  It converts the retrieved value to a String  The syntax is as follows: <jsp:getProperty name="id" property="propertyName" /> 56
  • 57. info.html and useBeanDemo.jsp <!-- info.html --> <form action=“useBeanDemo.jsp”> Name: <input name=“name”> Company: <input name=“company”> <input type=“submit” value=“Go!”> </form> ________________________________________ <%-- useBeanDemo.jsp --%> <jsp:useBean id="nameID" class="myBeans.Staff" /> <jsp:setProperty name="nameID" property="*" /> <jsp:getProperty name="nameID" property="name" /> <jsp:getProperty name="nameID" property="company" /> 57
  • 58. Result 58
  • 59. An Example The Bean – CounterBean.java package myBeans; import java.io.*; public class CounterBean implements Serializable { private int count; public int getCount() { Property return ++count; } get Method public void setCount(int c) { count = c; } set Method } 59
  • 60. An Example (cont.) The JSP that uses the bean Instantiate the <HTML> . . . Counter bean <jsp:useBean id="id_counter" scope="application" class="myBeans.CounterBean" /> <jsp:setProperty name="id_counter" property="count" /> <jsp:getProperty name="id_counter" property="count" /> . . . </HTML> 60
  • 61. Scope of Beans  By default, the objects created with jsp:useBean were bound to local variables in the _jspService method  The beans are also stored in one of four different locations, depending on the value of the optional scope attribute of jsp:useBean 61
  • 62. Scope of Beans (cont.)  page  This is the default value  References to this object will only be released after the response is sent back to the client  request  The bean instance will be available as long as the request object is available  References to this object will be released only after the request is processed completely 62
  • 63. Scope of Beans (cont.)  session  The instance will be available across a particular session between the browser of a particular machine and the Web server  References to this object will be released only after the associated sessions end  application  The instance will be available to all users and pages of the application  It is released only when the run-time environment reclaims the ServletContext 63
  • 64. Scope of Beans (cont.) 64
  • 65. An Example The Form – calculator1.html <HTML> . . . Enter any two numbers and click on the <B>Calculate</B> Button. <FORM ACTION = “useBean1.jsp"> Value1: <INPUT NAME = "value1"> Value2: <INPUT NAME = "value2"> <INPUT TYPE = "SUBMIT" VALUE = "Calculate"> . . . </HTML> 65
  • 66. An Example (cont.) The JSP – useBean1.jsp <jsp:useBean id="calc" class="myBeans.CalcBean" /> <jsp:setProperty name="calc" property="*" /> <B> The sum of the two numbers is <jsp:getProperty name="calc" property="sum" /></B> 66
  • 67. An Example (cont.) The Bean – CalcBean.java public class CalcBean implements java.io.Serializable { private int value1; private int value2; private int sum; public void setValue1(int num1) { value1 = num1; } public void setValue2(int num2) { value2 = num2; } public int getSum() { return value1 + value2; } 67 }
  • 68. Result 68
  • 69. JSP Standard Actions  JSP actions have the following characteristics:  These tags are case-sensitive  These are standard set of actions, supported by all containers  Attribute values must be enclosed within quotes  Tags must have a closing delimiter  New actions can be built  Existing actions can be extended  Actions can be put into the output buffer  Actions can access, modify, and create objects on the current server pages. 69
  • 70. Comparison of Servlet and JSP Servlet JSP  HTML code in  Java code in Java HTML  Any form of Data  Structured Text  Not easy to author  Very easy to author  Underlying semantics  Code is compiled into a servlet 70
  • 71. Comparison of Servlet and JSP (cont.) 71
  • 72. Recommended Uses of JSP  Application logic separated from Web content and embedded in components.  Present dynamic portions of content, which is tailored to a specific use.  Display repetitive portions of a Web site such as a header, a footer and a navigation bar. 72
  • 74. MVC pattern (Model 2)  Model 1 Architecture  JavaBean (Model) to represent the business logic  JSP (View) to handle all the request processing and provide the presentation  Model 2 Architecture (Model-View-Controller)  Often called the "MVC" or "Model 2" approach to JSP  JavaBean (Model) to represent the business logic  JSP (View) to provide the presentation  Servlet (Controller) to handle all the request processing 74
  • 75. Model 2 Architecture as MVC 75
  • 76. Best practice suggestion  For complex pages, use both  Servlet get request, validate and process  forward() to JSP for dynamic generated response  pass information as request attributes 76
  • 77. A Typical Web Application A flexible application with Java Servlet Servlet Web Client JSP 77
  • 78. Servlet : WelcomeName.java :: String name == request.getParameter("username"); String name request.getParameter("username"); request.setAttribute("name", name); request.setAttribute("name", name); RequestDispatcher rd == request.getRequestDispatcher("welcomeName.jsp"); RequestDispatcher rd request.getRequestDispatcher("welcomeName.jsp"); rd.forward(request, response); rd.forward(request, response); :: 78
  • 79. JSP : welcomeName.jsp <img src="Duke.png"> <img src="Duke.png"> <%= request.getAttribute("name") %> <%= request.getAttribute("name") %> 79
  • 80. Servlet/JSP Integration  Joint servlet/JSP process:  Original request is answered by a servlet  Servlet processes request data, does database lookup,business logic, etc.  Results are placed in beans  Request is forwarded to a JSP page to format result  Different JSP pages can be used to handle different types of presentation 80
  • 81. Separate Business Logic From Presentation 81
  • 82. Servlet : HelloName.java :: String name = request.getParameter("username"); String name = request.getParameter("username"); myBeans.Person obj = new myBeans.Person(); myBeans.Person obj = new myBeans.Person(); obj.setName(name); obj.setName(name); request.setAttribute("user", obj); request.setAttribute("user", obj); RequestDispatcher rd = RequestDispatcher rd = request.getRequestDispatcher(“helloName.jsp"); request.getRequestDispatcher(“helloName.jsp"); rd.forward(request, response); rd.forward(request, response); :: 82
  • 83. JSP : helloName.jsp <img src="Duke.png"> <img src="Duke.png"> <jsp:useBean id="user" class="myBeans.Person" scope="request" /> <jsp:useBean id="user" class="myBeans.Person" scope="request" /> <jsp:getProperty name="user" property="name" /> <jsp:getProperty name="user" property="name" /> 83
  • 84. Java Bean : Person.java package myBeans; package myBeans; public class Person { public class Person { private String name; private String name; public void setName(String name) { public void setName(String name) { this.name = name; this.name = name; }} public String getName() { public String getName() { return name; return name; }} }} 84
  • 85. Servlet, JSP & Java Bean 85
  • 86. A Typical Web Application JSP combined with Enterprise JavaBeans technology HTTP/HTML/XML Browser JSP EJBs RMI/IIOP 86
  • 87. Thank you thananum@gmail.com www.facebook.com/imcinstitute www.imcinstitute.com 87