java 2 enterprises edition j2ee
Download
Skip this Video
Download Presentation
Java 2 Enterprises Edition (J2EE)

Loading in 2 Seconds...

play fullscreen
1 / 40

Java 2 Enterprises Edition (J2EE) - PowerPoint PPT Presentation


  • 238 Views
  • Uploaded on

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 What is JSP? Stands for Java Server Pages

loader
I am the owner, or an agent authorized to act on behalf of the owner, of the copyrighted work described.
capcha
Download Presentation

PowerPoint Slideshow about 'Java 2 Enterprises Edition (J2EE)' - ostinmannual


An Image/Link below is provided (as is) to download presentation

Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author.While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server.


- - - - - - - - - - - - - - - - - - - - - - - - - - E N D - - - - - - - - - - - - - - - - - - - - - - - - - -
Presentation Transcript
java 2 enterprises edition j2ee

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

what is jsp
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
what is jsp3
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
review static vs dynamic web pages
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

review static vs dynamic web pages cont
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.
review static vs dynamic web pages cont6
Review Static vs. Dynamic Web pages (cont.)

Server

(Web Application)

request

Client

(Web browser)

Server

(generate Web page)

response

other methods to create dynamic web pages cgi
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/)
other methods to create dynamic web pages server apis
Other methods to create dynamic Web pages (Server APIs)
  • Web server specific API
    • Netscape’s Web Application Interface (WAI)
    • Microsoft’s 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.
other methods to create dynamic web pages client side scripting
Other methods to create dynamic Web pages (Client-side scripting)
  • Merits:
    • Very useful to create client-side scripting
    • Computing is performed on the client’s machine
    • More secure and efficient
other methods to create dynamic web pages client side scripting10
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.
other methods to create dynamic web pages server side scripting
Other methods to create dynamic Web pages (Server-side scripting)
  • Scripts run on the server before the page is sent to user
  • Netscape’s Server Side JavaScript (SSJS)
    • Script is executed on the server to modify HTML pages and scripts are pre-compiled to improve server performance
other methods to create dynamic web pages server side scripting12
Other methods to create dynamic Web pages (Server-side scripting)
  • Microsoft’s 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 MS’s Internet Information Server 3.0 or later
    • Platform dependent.
other methods to create dynamic web pages java applets
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 client’s machines
  • Loading Byte files through internet.
other methods to create dynamic web pages java servlets
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 J2EE’s Java Servlet technology
mechanism of jsp
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
mechanism of jsp16
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 "<%" and "%>" to note the start and end of a JSP section, respectively.
mechanism of jsp17
Mechanism of JSP

Server Page Engine

request

Client

(Web browser)

Template Page

response

Generate Web Page

power of jsp
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
power of jsp19
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
power of jsp20
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/
helloworld jsp
HelloWorld.jsp

HelloWorld JSP Version

Hellow World from JSP!

That is nothing but html syntax!

You can write .jsp file instead of .html file

URL: http://localhost:8100/HelloWorld.jsp

simpledate html static
simpleDate.html (static)

A simple date example

The time on the server is

Friday June 8 15:12:09 PST 2001

URL: http://localhost:8100/simpleDate.html

simpledate jsp dynamic
simpleDate.jsp (dynamic)

A simple date example

The time on the server is

<%= new java.util.Date() %>

URL: http://localhost:8100/simpleDate.jsp

helloworldloop jsp
HelloWorldLoop.jsp

Greetings

<%

for(int i=0;i<5;i++)

{ %>

Hello World!

<% } %>

Interesting to embedded

Java into html syntax

URL: http://localhost:8100/HelloWorld.jsp

jsp helloworld lopp in servlet version
JSP HelloWorld Lopp in Servlet version

Alternatively you can explicitly write your code in term of servlet Java code, for example

example servlet based java code helloworldservletloop java
Example: Servlet based Java codeHelloWorldServletLoop.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/html");

out.println(" ");

for(int i=0;i<10;i++)

out.println("Hello World!
");

out.println(" ");

out.close();

}

}

slide27
Compile HelloWorldServletLoop.java

URL: http://localhost:8100/servlet/HelloWorldServletLoop

scripting elements of jsp
Scripting Elements of JSP
  • 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)

JSPs combine HTML with special tags that define dynamic behaviors. The tags have the following features:

scripting elements of jsp29
Scripting Elements of JSP
  • Different formats for JSP elements (Tag formats)
    • JSP syntax: <% script code %> (recommended)
    • XML standard syntax:
jsp s scriptlet
JSP's Scriptlet
  • JSP syntax:
    • <% script code %>
    • code
  • 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 "<%" and "%>" tags
  • For example:
example date jsp
Example: date.jsp

Current date is displayed using JSP's Scriptlet

Current date is displayed using JSP's Scriptlet

The current date is:

<% out.println(new java.util.Date()); %>

Small bits of Java code

URL: http://localhost:8100/date.jsp

example scriptlethelloworld jsp
Example: ScriptletHelloWorld.jsp

Dynamic HelloWorld JSP Version

HelloWorld using JSP Scriptle version


The content of the Web materials is based on if-else with 50% randomization.


Either Albert Gore or Patrick Buchanan.

In order to test, please keep re-loading or re-flashing.

example scriptlethelloworld jsp33
Example: ScriptletHelloWorld.jsp

<%double chad=Math.random();

if (chad<0.5) {%>

Albert Gore

<%} else {%>

Patrick Buchanan

<%}%>


Dynamic control

http://localhost:8100/ScriptletHelloWorld.jsp

jsp s expressions
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: <% out.println(Math.random() ) ; %>

Expression: <% =math.radom() %>

slide35

<%! public java.util.Date PrintDate()

{

return(new java.util.Date());

}

%>

Current Date

The current date is:

<%= PrintDate() %>

jsp s declaration
JSP's Declaration
  • Declaration: is used to declare methods and variables that are initialized with the page.
jsp s directives
JSP's Directives
  • Directive contains global information that is applicable to the whole page.
jsp s action
JSP's Action
  • Provide information for the translation phase of the JSP page and consist of a set of standard, built-in methods
jsp reference
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.apache.org)
  • Jrun server (http://www.jrun.com)
jsp reference40
JSP Reference
  • Javasoft’s JSP web site (http://java.sun.com/products/jsp/index.html)
  • Tomcat’s F&Q (http://java.sun.com/products/jsp/tomcat/faq.html)
  • JSP’s Tagkib
  • (http://jakarta.apache.org/taglibs)