Java 2 Enterprises Edition (J2EE) - PowerPoint PPT Presentation

1 / 40
About This Presentation
Title:

Java 2 Enterprises Edition (J2EE)

Description:

The content of the Web materials is based on if-else with 50% randomization. br ... JSP's Tagkib (http://jakarta.apache.org/taglibs) ... – PowerPoint PPT presentation

Number of Views:86
Avg rating:3.0/5.0
Slides: 41
Provided by: academ75
Category:

less

Transcript and Presenter's Notes

Title: Java 2 Enterprises Edition (J2EE)


1
Java 2 Enterprises Edition (J2EE)
  • Java Server Pages (JSP) Technology

Jun Ni, Ph.D.M.E. Academic Technology,
ITS Department of Computer Science The
University of Iowa June 5, 2001
2
What is JSP?
  • Stands for Java Server Pages
  • New technology for creating dynamic web content
    to be with Java codes
  • Server-side computing
  • Portable by supporting the JavaBean and
    Enterprises JavaBean component models

3
What is JSP?
  • The base of JSP is Java Servlet technology
  • Simplified Java Servlet programming
  • Convert JSP to Servlet automatically
  • De-couple business logic and presentation
  • Does not do page layout design

4
Review Static vs. Dynamic Web pages
  • With a static Web page, the client requests a Web
    page from the Web server, and the server responds
    by sending back the requested file to the client.
    Then client displays the file.

request
Server (maintain static Web page)
Client (Web browser)
response
5
Review Static vs. Dynamic Web pages (cont.)
  • In dynamic Web design, the content of the page is
    generated at the time when it is requested, or
    changed the content based on client requested
    criteria. It is generated by application on the
    server, receiving input from the client,
    computing on the server, and responding back to
    the client.

6
Review Static vs. Dynamic Web pages (cont.)
Server (Web Application)
request
Client (Web browser)
Server (generate Web page)
response
7
Other methods to create dynamic Web pages (CGI)
  • Most prolific from of Web application in use
    today.
  • Requests to be sent to an external program, in
    Perl, C/C, or other languages
  • Shortcomings using CGI
  • Large amount of system resources
  • Independent from Web server
  • Not portable to other platforms
  • FastCGI (http//www.fastengines.com/)
  • Apache Web server (http//perl.apache.org/)
  • PerlEx (http//www.activestate.com/plex/)

8
Other methods to create dynamic Web pages (Server
APIs)
  • Web server specific API
  • Netscapes Web Application Interface (WAI)
  • Microsofts Internet Information Server (ISAPI)
  • Tremendous performance speed and resources
  • Limited to particular platform and Web server
  • Server API extension can create several security
    issues, since it is as part of the Web server,
    which could cause the Web server to crash.

9
Other methods to create dynamic Web pages
(Client-side scripting)
  • Merits
  • Very useful to create client-side scripting
  • Computing is performed on the clients machine
  • More secure and efficient

10
Other methods to create dynamic Web pages
(Client-side scripting)
  • drawbacks
  • Client needs to support the scripting language in
    exactly the ways expected
  • Differences between web browsers due to the
    interpretation of client-side scripts.
  • Various scripts (JavaScript (Nescape,
    Jscript(MS), VBScript (MS), ECMAScript
    (ECMA-262).
  • Can not access server-side database
  • JavaScript and JSP plays a different rule
  • The best technology is to combine them together.

11
Other methods to create dynamic Web pages
(Server-side scripting)
  • Scripts run on the server before the page is sent
    to user
  • Netscapes Server Side JavaScript (SSJS)
  • Script is executed on the server to modify HTML
    pages and scripts are pre-compiled to improve
    server performance

12
Other methods to create dynamic Web pages
(Server-side scripting)
  • Microsofts Active Server Pages (ASP)
  • Very similar to JSP
  • Allows developer to embed VBScript or Jscript
    code directly into a Web page.
  • The ASP pages have to be compiled every time they
    run.
  • Only available to MSs Internet Information
    Server 3.0 or later
  • Platform dependent.

13
Other methods to create dynamic Web pages (Java
applets)
  • Java applets are pre-designed by Web developers
  • They can be executed of client-side of machine.
  • They can be used for certain dynamic features
    such as multimedia and interactive Web
    application
  • Can not applied to database or file system
  • Performance depends on clients machines
  • Loading Byte files through internet.

14
Other methods to create dynamic Web pages (Java
servlets)
  • Opposite to Java applets, which are small Web
    applications run on the client side, Java
    servlets are powerful alternative to CGI programs
    and scripting languages
  • Easy to be ported to any environment that
    supports the Servlet API.
  • Bypassing the security problems that effect the
    server APIs, since they run in Java VM.
  • Scalable and supported by all major Web servers
  • Drawback Java programming
  • See J2EEs Java Servlet technology

15
Mechanism of JSP
  • JSP is extremely powerful fro Web Applications
  • JSP is a technology using server-side script that
    is actually translated into Servlets and compiled
    before they are run.
  • It provides developers a scripting interface to
    create powerful Java Servlets
  • JSP provides tags that allows developers to
    perform most dynamic content operations without
    writing complex java code.
  • Advanced Java Programmers can perform advanced
    operations in JSP pages

16
Mechanism of JSP
  • On a server page, the client requests a Web page,
    server replaces some sections of a template with
    new data, and send this newly modified page to
    client.
  • JSP has special tags "lt" and "gt" to note the
    start and end of a JSP section, respectively.

17
Mechanism of JSP
Server Page Engine
request
Client (Web browser)
Template Page
response
Generate Web Page
18
Power of JSP
  • Write once and run anywhere
  • No AWT and Swing
  • Full power of Java API including networking,
    multithreading, database connectivity,
    internationalization, image manipulation, object
    serialization, RMI, CORBA, JNDI, Mail API, Java
    classes, JavaBeans and Enterprise JavaBeans
  • Communicate with Java Applet directly for
    advanced client server application development

19
Power of JSP
  • Security and safety (avoid memory issues with
    automatic garbage collections and absence of
    pointers established exception Java security
    manager)
  • Scalability
  • Extensibility (Java servlet extensions support
    other scripting languages close relationship to
    XML
  • Components JavaBean component framework

20
Power of JSP
  • How to run your JSP on your web server?
  • You need to download JRUN from Allaire
    (Macromedia). Web site http//www.jrun.com/
  • You can also download from Apache software (
    foundation's (http//www.apache.org/ ) Javarta
    project web site at http//jakarta.apache.org/

21
HelloWorld.jsp
lthtmlgt ltheadgt lttitlegtHelloWorld JSP
Versionlt/titlegt lt/headgt ltbodygt Hellow World from
JSP! lt/bodygt lt/htmlgt
That is nothing but html syntax! You can write
.jsp file instead of .html file
URL http//localhost8100/HelloWorld.jsp
22
simpleDate.html (static)
lt!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0
Final//EN"gt ltHTMLgt ltHEADgt ltTITLEgtA simple date
examplelt/TITLEgt lt/HEADgt ltBODY COLORffffffgt The
time on the server is Friday June 8 151209 PST
2001 lt/BODYgt lt/HTMLgt
URL http//localhost8100/simpleDate.html
23
simpleDate.jsp (dynamic)
lt!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0
Final//EN"gt ltHTMLgt ltHEADgt ltTITLEgtA simple date
examplelt/TITLEgt lt/HEADgt ltBODY COLORffffffgt The
time on the server is lt new java.util.Date()
gt lt/BODYgt lt/HTMLgt
URL http//localhost8100/simpleDate.jsp
24
HelloWorldLoop.jsp
lthtmlgt ltheadgt lttitlegtGreetingslt/titlegtlt/headgt ltbod
ygt lt for(int i0ilt5i) gt lth1gtHello
World!lt/h1gt lt gt lt/bodygt lt/htmlgt
Interesting to embedded Java into html syntax
URL http//localhost8100/HelloWorld.jsp
25
JSP HelloWorld Lopp in Servlet version
Alternatively you can explicitly write your code
in term of servlet Java code, for example
26
Example Servlet based Java codeHelloWorldServlet
Loop.java
import javax.servlet. import javax.servlet.http.
import java.io. public class
HelloWorldServletLoop extends HttpServlet
public void service (HttpServletRequest req,
HttpServletResponse res) throws
IOException PrintWriter out
res.getWriter() res.setContentType("text/ht
ml") out.println("ltHTMLgt ltBODYgt ")
for(int i0ilt10i) out.println("Hello
World!ltBRgt") out.println("ltBODYgt lt/HTMLgt
") out.close()
27
Compile HelloWorldServletLoop.java URL
http//localhost8100/servlet/HelloWorldServletLoo
p
28
Scripting Elements of JSP
JSPs combine HTML with special tags that define
dynamic behaviors. The tags have the following
features
  • Scriptlets (embedded into HTML page)
  • Expressions (access value of Java code)
  • Declarations (define methods and variables for
    initialization)
  • Directives (apply global information to the page)
  • Actions (information for translation phase)

29
Scripting Elements of JSP
  • Different formats for JSP elements (Tag formats)
  • JSP syntax lt script code gt (recommended)
  • XML standard syntax ltjspelement /gt

30
JSP's Scriptlet
  • JSP syntax
  • lt script code gt
  • ltjspscriptletgt code lt/jspscriptletgt
  • Small bits of Java code inserted into JPS pages
  • Scriplets may contain single or multiple
    statements
  • Scriplets may be combined with original HTML to
    provide dynamic control
  • Scriplets use "lt" and "gt" tags
  • For example

31
Example date.jsp
lt!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0
Final//EN"gt ltHTMLgt ltHEADgt ltTITLEgtCurrent date is
displayed using JSP's Scriptletlt/TITLEgtlt/HEADgt ltB
ODYgt lth1gt Current date is displayed using JSP's
Scriptlet lt/h1gt The current date is lt
out.println(new java.util.Date()) gt
lt/BODYgt lt/HTMLgt
Small bits of Java code
URL http//localhost8100/date.jsp
32
Example ScriptletHelloWorld.jsp
lthtmlgt ltheadgt lttitlegtDynamic HelloWorld JSP
Versionlt/titlegt lt/headgt ltbodygt ltcentergtltfont
size5gtHelloWorld using JSP Scriptle
versionlt/fontgtlt/centergt ltbrgt The content of the
Web materials is based on if-else with 50
randomization. ltbrgt Either Albert Gore or Patrick
Buchanan. ltpgt In order to test, please keep
re-loading or re-flashing.
33
Example ScriptletHelloWorld.jsp
ltpgt ltdouble chadMath.random() if (chadlt0.5)
gt Albert Gore lt else gt Patrick
Buchanan ltgt ltbrgt lt/bodygtlt/htmlgt
Dynamic control
http//localhost8100/ScriptletHelloWorld.jsp
34
JSP's Expressions
  • Expression JSP allows developers to insert the
    value of a Java expression directly into a web
    page.
  • Expression do not end with a semi-colon and must
    evaluate to a basic type or String
  • It uses "" sign.

Scriptlet lt out.println(Math.random() )
gt Expression lt math.radom() gt
35
lt!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0
Final//EN"gt lt! public java.util.Date
PrintDate() return(new
java.util.Date()) gt ltHTMLgt ltHEADgt ltTITLE
gtCurrent Datelt/TITLEgt lt/HEADgt ltBODYgt The current
date is lt PrintDate() gt lt/BODYgt lt/HTMLgt
36
JSP's Declaration
  • Declaration is used to declare methods and
    variables that are initialized with the page.

37
JSP's Directives
  • Directive contains global information that is
    applicable to the whole page.

38
JSP's Action
  • Provide information for the translation phase of
    the JSP page and consist of a set of standard,
    built-in methods

39
JSP Reference
  • W3C (http//www.w3.org/)
  • Apache software foundation (http//www.apache.org)
  • Sun Java resources (http//www.javasoft.com)
  • Tomcat, small-scale web server (http//jakarta.apa
    che.org)
  • Jrun server (http//www.jrun.com)

40
JSP Reference
  • Javasofts JSP web site (http//java.sun.com/produ
    cts/jsp/index.html)
  • Tomcats FQ (http//java.sun.com/products/jsp/tom
    cat/faq.html)
  • JSPs Tagkib
  • (http//jakarta.apache.org/taglibs)
Write a Comment
User Comments (0)
About PowerShow.com