DT228/3 Web Development - PowerPoint PPT Presentation

1 / 18
About This Presentation
Title:

DT228/3 Web Development

Description:

First need to know the various 'java' related terms: ... Tomcat web server (nicknamed Catalina) Tomcat webserver incorporates JSP container ... – PowerPoint PPT presentation

Number of Views:15
Avg rating:3.0/5.0
Slides: 19
Provided by: fsdf
Category:

less

Transcript and Presenter's Notes

Title: DT228/3 Web Development


1
DT228/3 Web Development
Introduction to Java Server Pages (JSP)
2
Introduction
  • First need to know the various java related
    terms
  • J2EE, J2SE, JDK, JRE, JSP,JSTL, Java
    Servlets,Tomcat, Apache etc..

3
Introduction J2EE
  • Sun Microsystems supply the Java 2 Enterprise
    Edition(J2EE) platform, enabling developers to
    develop java based enterprise applications
  • J2EE is a standard set of technologies and APIs
  • (note J2SE is the standard edition of the java
    platform but is not geared at large enterprise
    environments with distributed systems)
  • J2EE includes the following components

Java Server Pages
Java beans
Servlets
Java Messaging
JNDI
JDBC
4
Introduction J2EE
  • Since J2EE is a specification, vendors create
    productsthat support the J2EE specifcation e.g.
    Apache, IBMWebSphere, BEA Weblogic.
  • From a web perspective, the J2EE applications
    that areparticularly relevant are
  • Java Server PagesJava servletsJava Beans

Can be used on its ownor with beans/servlets to
create a webapplication
Can be used on its ownor with JSP/beans to
create a webapplication
More complex web applications may use all 3
5
Introduction JDK
  • The (JDK) Java Development Kit is the collective
    name for the various development components
    supplied in the J2EE (or J2SE).
  • The Java Runtime Environment (JRE) is consists of
    the components required to run a java application

6
Introduction to JSP
  • Java Server Pages A technology for developing
    web
  • pages that include dynamic content
  • Created by SUN microsystems
  • Equivalent of Microsofts Active Server Pages
    technology
  • Pages have a file extension of .JSP
  • JSPs enable web developers to enhance HTML code
  • by adding special JSP elements that are
    processed by the
  • server
  • Will use JSP v2.0

7
Advantages of JSP
  • JSP pages are pre-compiled ? Fast
  • Part of the Suns J2EE -? Can be used with other
    types of java technologies, such as servlets -?
    flexible
  • JSP is a specification ? multiple vendors support
    it ? commercially stable/not fly by night
    technology
  • Easy to develop HTML can be easily maintained
    with JSP. Relatively minimal programming skills
    required.
  • JSP page code is not visible on client only
    generated HTML is visible

8
Running JSP pages
Not automatically included with all web servers
  • To develop and run JSP pages, need
  • - Java Developer Kit (JDK which is part of
    J2EE) or higher AND a Web server that contains a
    JSP Container
  • JSP Containers are not automatically included
    with all Web servers
  • Examples of web servers that contain a JSP
    container are Apache Tomcat and Blazix.

9
JSP Containers
  • JSP Container
  • The JSP Container intercepts all client request
    for JSP pages
  • First time a JSP page is requested, the Container
    converts the page into a java program called a
    Servlet and compiles --? Translation phase
  • For all follow-on request, the Container
    processes each request by invoking the
    appropriate servlet and then generating the
    response -? Request processing phase
  • Q What happens if the JSP page is changed?

10
How a JSP page is processed by server
First time through, JSP is translated to a
servlet After, container goes directly to the
servlet in the request processing phase
If JSP page is changed, servlet is re-compiled
11
JSP and Apache
  • Apache project have a sub project called
    Jakarta(see http//jakarta.apache.org/index2.html
    )
  • Jakarta project produces
  • Tomcat web server (nicknamed Catalina)
  • Tomcat webserver incorporates JSP container
    (nicknamed Jasper)

12
Software Versions
JSP technology developing rapidly ? New version
contain major new capabilities ? Always note the
JSP container version you are working with, and
check functionality supported (on apache
website) This course using Apache Tomcat Version
5 JSP 2 JSLT 1.1 Servlet 2.4
13
To run a JSP
Using apache Tomcat Create your web application
directory Create the subset WEB-INF directory
(wont run without this) Put JSP page into web
application directory Call from the
browser http//localhost8080/webapp/somename.jsp
14
To run a JSP
In the background Tomcat will retrieve the
JSP page from the web server If its the first
time JSP page has been called/run or if page has
changed, Tomcat will compile the JSP page (into a
servlet) - .java and .class placed in /work
directory. -? subsequent calls to page will be
faster as no compile needed JSP page will be
presented back to the user
15
Simplest JSP.. Helloworld
  • Prints out message to user when JSP is loaded..
  • Tomcat demo..

16
Another Simple JSP example
  • lthtmlgt
  • lt_at_ page import"java.util.Date" gt
  • ltheadgt
  • lttitlegtJSP DATE EXAMPLElt/titlegt
  • lt/headgt
  • ltbody bgcolorffffffgt
  • lth1gtJSP DATElt/h1gt
  • lth2gt
  • The current date is lt new Date() gt.
  • lt/h2gt
  • lt/bodygt
  • lt/htmlgt

Prints out the current date
17
Readability of JSP pages
  • Always always always ensure that code is
  • INDENTED COMMENTED CONTAINS AN ID
    BLOCK
  • Indented - to reflect level of the code
    lthtmlgt
  • ltheadgtajsdlkfjads etc
  • 2) Well commented. Comments in JSP appear
    aslt-- calculate the sum of x and z here --gt
  • Comments in HTML appear as lt!--- this is a
    comment --gt
  • HTML comments will be visible by view source in
    browser, JSP comments wont.

18
Readability of JSP pages
3) Titled with an ID block At the top of each
JSP page, should have an ID block explaining who
write the script, date, script name, description
and any revisions. Can use either JSP or HTML
comments (depending on whether users should be
able to see the ID block)
lt--
Script name addition.jsp
Author Keith Morneau
Date July 7th 2006
Desciption whatever it does..
Revisions
August 8th 2006 added subroutine
-
-gt etc
Write a Comment
User Comments (0)
About PowerShow.com