Java 2 enterprises edition j2ee
Download
1 / 40

J2EEJSPpresentation - 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 'J2EEJSPpresentation' - 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 l.jpg

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 l.jpg
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 l.jpg
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 l.jpg
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 l.jpg
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 l.jpg
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 l.jpg
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 l.jpg
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 l.jpg
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 l.jpg
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 l.jpg
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 l.jpg
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 l.jpg
Other methods to create dynamic Web pages (Java applets) scripting)

  • 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 l.jpg
Other methods to create dynamic Web pages (Java servlets) scripting)

  • 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 l.jpg
Mechanism of JSP scripting)

  • 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 l.jpg
Mechanism of JSP scripting)

  • 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 l.jpg
Mechanism of JSP scripting)

Server Page Engine

request

Client

(Web browser)

Template Page

response

Generate Web Page


Power of jsp l.jpg
Power of JSP scripting)

  • 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 l.jpg
Power of JSP scripting)

  • 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 l.jpg
Power of JSP scripting)

  • 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 l.jpg
HelloWorld.jsp scripting)

<html>

<head>

<title>HelloWorld JSP Version</title>

</head>

<body>

Hellow World from JSP!

</body>

</html>

That is nothing but html syntax!

You can write .jsp file instead of .html file

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


Simpledate html static l.jpg
simpleDate.html (static) scripting)

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Final//EN">

<HTML>

<HEAD>

<TITLE>A simple date example</TITLE>

</HEAD>

<BODY COLOR=#ffffff>

The time on the server is

Friday June 8 15:12:09 PST 2001

</BODY>

</HTML>

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


Simpledate jsp dynamic l.jpg
simpleDate.jsp (dynamic) scripting)

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Final//EN">

<HTML>

<HEAD>

<TITLE>A simple date example</TITLE>

</HEAD>

<BODY COLOR=#ffffff>

The time on the server is

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

</BODY>

</HTML>

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


Helloworldloop jsp l.jpg
HelloWorldLoop.jsp scripting)

<html>

<head>

<title>Greetings</title></head>

<body>

<%

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

{ %>

<h1>Hello World!</h1>

<% } %>

</body>

</html>

Interesting to embedded

Java into html syntax

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


Jsp helloworld lopp in servlet version l.jpg
JSP HelloWorld Lopp in Servlet version scripting)

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


Example servlet based java code helloworldservletloop java l.jpg
Example: Servlet based Java code scripting)HelloWorldServletLoop.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("<HTML> <BODY> ");

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

out.println("Hello World!<BR>");

out.println("<BODY> </HTML> ");

out.close();

}

}


Slide27 l.jpg

Compile HelloWorldServletLoop.java scripting)

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


Scripting elements of jsp l.jpg
Scripting Elements of JSP scripting)

  • 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 l.jpg
Scripting Elements of JSP scripting)

  • Different formats for JSP elements (Tag formats)

    • JSP syntax: <% script code %> (recommended)

    • XML standard syntax: <jsp:element />


Jsp s scriptlet l.jpg
JSP's Scriptlet scripting)

  • JSP syntax:

    • <% script code %>

    • <jsp:scriptlet> code </jsp:scriptlet>

  • 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 l.jpg
Example: date.jsp scripting)

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Final//EN">

<HTML>

<HEAD>

<TITLE>Current date is displayed using JSP's Scriptlet</TITLE></HEAD>

<BODY>

<h1> Current date is displayed using JSP's Scriptlet </h1>

The current date is:

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

</BODY>

</HTML>

Small bits of Java code

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


Example scriptlethelloworld jsp l.jpg
Example: ScriptletHelloWorld.jsp scripting)

<html>

<head>

<title>Dynamic HelloWorld JSP Version</title>

</head>

<body>

<center><font size=5>HelloWorld using JSP Scriptle version</font></center>

<br>

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

<br>

Either Albert Gore or Patrick Buchanan.

<p>

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


Example scriptlethelloworld jsp33 l.jpg
Example: ScriptletHelloWorld.jsp scripting)

<p>

<%double chad=Math.random();

if (chad<0.5) {%>

Albert Gore

<%} else {%>

Patrick Buchanan

<%}%>

<br>

</body></html>

Dynamic control

http://localhost:8100/ScriptletHelloWorld.jsp


Jsp s expressions l.jpg
JSP's Expressions scripting)

  • 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 l.jpg

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Final//EN"> scripting)

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

{

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

}

%>

<HTML>

<HEAD>

<TITLE>Current Date</TITLE>

</HEAD>

<BODY>

The current date is:

<%= PrintDate() %>

</BODY>

</HTML>


Jsp s declaration l.jpg
JSP's Declaration scripting)

  • Declaration: is used to declare methods and variables that are initialized with the page.


Jsp s directives l.jpg
JSP's Directives scripting)

  • Directive contains global information that is applicable to the whole page.


Jsp s action l.jpg
JSP's Action scripting)

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


Jsp reference l.jpg
JSP Reference scripting)

  • 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 l.jpg
JSP Reference scripting)

  • 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)


ad