04/18/20011 JavaServer Page Presented by: Hongmei Yu 04/18/2001.

Slides:



Advertisements
Similar presentations
JavaScript FaaDoOEngineers.com FaaDoOEngineers.com.
Advertisements

Java Server Pages Jeffrey Jongko. Introduction Java Server Pages (JSP) technology was created by Sun Microsystems and is built on top of Sun’s Java Servlet.
Apache Struts Technology
 Copyright Wipro Technologies JSP Ver 1.0 Page 1 Talent Transformation Java Server Pages.
DT228/3 Web Development WWW and Client server model.
Copyright 2004 Monash University IMS5401 Web-based Systems Development Topic 2: Elements of the Web (g) Interactivity.
JSP: JavaServer Pages Juan Cruz Kevin Hessels Ian Moon.
Sapana Mehta (CS-6V81) Overview Of J2EE & JBoss Sapana Mehta.
28/1/2001 Seminar in Databases in the Internet Environment Introduction to J ava S erver P ages technology by Naomi Chen.
Kashif Jalal CA-240 (072) Web Development Using ASP.NET CA – 240 Kashif Jalal Welcome to week – 2 of…
Java Server Pages Russell Beale. What are Java Server Pages? Separates content from presentation Good to use when lots of HTML to be presented to user,
Comp2513 Java Server Pages Daniel L. Silver, Ph.D.
Application Architectures Vijayan Sugumaran Department of DIS Oakland University.
1 Java Server Pages Can web pages be created specially for each user? What part does Java play?
Computer Science 101 Web Access to Databases Overview of Web Access to Databases.
2440: 141 Web Site Administration Web Server-Side Programming Professor: Enoch E. Damson.
Java Enterprise Edition Java Web Development Structure of a web project Introduction to Web Applications The first project Introduction to Java Web Development.
Christopher M. Pascucci Basic Structural Concepts of.NET Browser – Server Interaction.
UNIT-V The MVC architecture and Struts Framework.
Java Server Pages (JSP) Presented by: Ananth Prasad & Alex Ivanov May 10, 2001.
Overview of JSP Technology. The need of JSP With servlets, it is easy to – Read form data – Read HTTP request headers – Set HTTP status codes and response.
DAT602 Database Application Development Lecture 15 Java Server Pages Part 1.
INTRODUCTION TO WEB DATABASE PROGRAMMING
Java Server Pages CS-422. What are JSPs A logical evolution of java servlets –most servlets dynamically create HTML and integrate it with some computational.
Netbeans – jsp.zip Introduction to JSP Netbeans – jsp.zip.
M. Taimoor Khan * Java Server Pages (JSP) is a server-side programming technology that enables the creation of dynamic,
FALL 2005CSI 4118 – UNIVERSITY OF OTTAWA1 Part 4 Web technologies: HTTP, CGI, PHP,Java applets)
CSCI 6962: Server-side Design and Programming Course Introduction and Overview.
CIS 285 ROBINSON WINTER 2005 CIS 285 Web Application Development with Java CIS 285 Sinclair Community College Instructor: Mary Robinson.
Chapter 16 The World Wide Web Chapter Goals Compare and contrast the Internet and the World Wide Web Describe general Web processing Describe several.
Basics of Web Databases With the advent of Web database technology, Web pages are no longer static, but dynamic with connection to a back-end database.
Using JavaBeans and Custom Tags in JSP Lesson 3B / Slide 1 of 37 J2EE Web Components Pre-assessment Questions 1.The _____________ attribute of a JSP page.
JSP Java Server Pages Softsmith Infotech.
Chapter 7 Java Server Pages. Objectives Explain how the separation of concerns principle applies to JSP Describe the operation and life-cycle of a JSP.
Introduction to JavaServer Pages (JSP) Slides from Dr. Mark Llewellyn.
Java Server Pages Lecture July Java Server Pages Java Server Pages (JSPs) provide a way to separate the generation of dynamic content (java)
 Embeds Java code  In HTML tags  When used well  Simple way to generate dynamic web-pages  When misused (complex embedded Java)  Terribly messy.
Chapter 8 Script-free pages. Problem with scripting in JSP When you use scripting (declaration, scriplet, expressions) in your JSP, you actually put Java.
J2EE Structure & Definitions Catie Welsh CSE 432
Client Scripting1 Internet Systems Design. Client Scripting2 n “A scripting language is a programming language that is used to manipulate, customize,
JAVA SERVER PAGES. 2 SERVLETS The purpose of a servlet is to create a Web page in response to a client request Servlets are written in Java, with a little.
JAVA SERVER PAGES CREATING DYNAMIC WEB PAGES USING JAVA James Faeldon CS 119 Enterprise Systems Programming.
Webcommerce Computer Networks Webcommerce by Linnea Reppa Douglas Martindale Lev Shalevich.
Active Server Pages  In this chapter, you will learn:  How browsers and servers interacted on the Internet when the Internet first became popular 
1 MSCS 237 Overview of web technologies (A specific type of distributed systems)
Java server pages. A JSP file basically contains HTML, but with embedded JSP tags with snippets of Java code inside them. A JSP file basically contains.
Copyright © 2002 ProsoftTraining. All rights reserved. JavaServer Pages.
Overview of Form and Javascript fundamentals. Brief matching exercise 1. This is the software that allows a user to access and view HTML documents 2.
ASP (Active Server Pages) by Bülent & Resul. Presentation Outline Introduction What is an ASP file? How does ASP work? What can ASP do? Differences Between.
An Introduction to JavaServer™ Pages Prepared by Nicole Swan.
An Introduction to JavaServer™ Pages Prepared by Nicole Swan.
JSP BASICS AND ARCHITECTURE. Goals of JSP Simplify Creation of dynamic pages. Separate Dynamic and Static content.
CS562 Advanced Java and Internet Application Introduction to the Computer Warehouse Web Application. Java Server Pages (JSP) Technology. By Team Alpha.
© FPT SOFTWARE – TRAINING MATERIAL – Internal use 04e-BM/NS/HDCV/FSOFT v2/3 JSP Application Models.
Basic JSP Celsina Bignoli Problems with Servlets Servlets contain –request processing, –business logic –response generation all lumped.
Chapter 3 JSP Overview. The Problem with Servlets processing the request and generating the response are both handled by a single servlet class Java programming.
ASP-2-1 SERVER AND CLIENT SIDE SCRITPING Colorado Technical University IT420 Tim Peterson.
1 Java Server Pages A Java Server Page is a file consisting of HTML or XML markup into which special tags and code blocks are inserted When the page is.
Chapter 6 Chapter 6 Server Side Programming (JSP) Part 1 1 (IS 203) WebProgramming (IS 203) Web Programming.
Java Programming: Advanced Topics 1 Building Web Applications Chapter 13.
Java Server Pages. 2 Servlets The purpose of a servlet is to create a Web page in response to a client request Servlets are written in Java, with a little.
Chapter 14 Using JavaBeans Components in JSP Documents.
Bayu Priyambadha, S.Kom. Static content  Web Server delivers contents of a file (html) 1. Browser sends request to Web Server 3. Web Server sends HTML.
A Presentation Presentation On JSP On JSP & Online Shopping Cart Online Shopping Cart.
1 Chapter 1 INTRODUCTION TO WEB. 2 Objectives In this chapter, you will: Become familiar with the architecture of the World Wide Web Learn about communication.
Java Server Pages Can web pages be created specially for each user?
Scripted Page Web App Development (Java Server Pages)
Design and Maintenance of Web Applications in J2EE
Java Server Pages (JSP)
Scripted Page Web Application Development (Java Server Pages)
Presentation transcript:

04/18/20011 JavaServer Page Presented by: Hongmei Yu 04/18/2001

2 JavaServer Page What is a JavaServer Page? Why to Use JavaServer Page JSP and JavaBeans JSP Session Two Basic Ways of Using JSP Tecnology Final words

04/18/20013 Introduction to JavaServer Page JavaServer Pages are text files that combine standard HTML and new scripting tags. JSPs are look like HTML, but they get compiled into Java servlets the first time they are invoked. The resulting servlet is a combination of the HTML from the JSP file and embedded dynamic content specified by the new tags.

04/18/20014 What is a JavaServer Page Definition: JSP is a dynamic capability for web pages that allows java as well as a few special tags to be embedded into a web file(HTML/XML, etc). The suffix traditionally ends with.jsp to indicate to the web server that the file is a JSP file. JSP is a server side technology.

04/18/20015 A simple Example Simple JSP Example How many times? The main HTML file(SimpleJSP.html)

04/18/20016 A simple Example Simple JSP Example <% int numTimes = Integer.parseInt(request.getParameter("numtimes")); for (int i = 0; i < numTimes; i++) { %> CSI 668! <% } %> The response file(SimpleJSP.jsp)

04/18/20017 JSP directives: Sets attributes for the page 1.page directive --defines a number of important attributes that affect the whole page. 2.include directive --notifies the container to include the content of the resource in the current JSP.The included file is parsed by the JSP and this happens only at translation time. 3.taglib directive --Allows the page to use custom user defined tags. taglib uri=“tagLibraryURI” prefix=“tagPrefix” %>

04/18/20018 Scripting Elements —are used to include scripting code (normally java code) within the JSP. 1.Declarations 2.Scriptlets 3.Expressions

04/18/20019 Standard Actions affect the runtime behavior of the JSP affect the response sent back to the client

04/18/ BrowserServer User enters value into form and clicks submit button Response displayed in browser window Interprets JSP and uses data from form to generate response Time Sends requests to server For JSP page, including Data from form Sends response to browser Containing HTML code

04/18/200111

04/18/ Comparison with Existing Technologies CGI(Common Gateway Interface) –The simplest and oldest way to use an HTTP request to control the HTTP output of a server-side application. –Required loading/unloading of application each time. –Used interpreted languages usually(PERL, C++, or Python). By comparison: 1.JSP can maintain state on the server between requests(since it can use Servlet sessions). 2.Spawns a new thread for each request. 3.Does not have to be loaded each time, once it has been initiated. 4.Runs in a ready-loaded JVM as an extension to the web server.

04/18/ Comparison with Existing Technologies Web Server APIs --Many web servers have their own built-in APIs for creating dynamic content. ISAPI for Microsoft IIS NSAPI for Netscape web servers --When using a server API, the code is written specifically for that web server and particular platform.

04/18/ Comparison with Existing Technologies Client_Side Scripting(JavaScript, Jscript, VBScript) Vary interpretations by different browser versions. A user can also decide to disable scripting altogether. Since JSP runs on the server as such, the browser is not an issue(unless the JSP products HTML code which contains client side scripting code.)

04/18/ Comparison with Existing Technologies Servlets Servlets provide the ability to build dynamic content for web sites using the Java language, and are supported on all major web server platforms. The JSP specification is built on top of the Java Servlet API.Anything that can be done with a JSP can be done with a Servlet. JSPs provide a much cleaner separation of presentation from logic, and are simpler to write. Servlets and JSP are work well together.

04/18/ JSP ASP Comparison with Existing Technologies ASP Platforms All major web platformsMicrosoft only Base Language Java Jscript or VBScript Components JSP Tags, JavaBeans, or COM/DCOM Enterprise JavaBeans Code InterpretationOnce Each instance

04/18/ Comparison with Existing Technologies JSPs score over ASP in that: JSPs are interpreted only once, to Java byte-code, and re-interpreted only when the file is modified. JSPs run on all the main web servers JSPs provide better facilities for separation of page code and template data by means of JavaBeans, Enterprise JavaBeans and custom tag libraries. ASP

04/18/ Why to use JavaServer Page Easy and Rapid Web Development,and Maintenance Easy and Rapid Web Development,and Maintenance Emphasizing Reusable Components Emphasizing Reusable Components Separating Content Generation from Presentation Separating Content Generation from Presentation Platform Independence Platform Independence Simplifying Page Development with Tags Simplifying Page Development with Tags

04/18/ JSP and JavaBeans  The JavaBeans specification allows software components to be written in Java. This means reusable bean classes can be defined, greatly reducing future maintaince requirements.  A property of a JavaBean is simply the data (state) of the bean. Properties are accessible by two methods: the getter and the setter. The value of the property is accessed by the getter method. If the property is writeable, its value is changed by the setter method. Loading a Bean - Initializing a Bean - Displaying Dynamic Content -

04/18/ JSP and JavaBeans JSP:useBean action is used to associate a JavaBean with the JSP. <jsp: useBean id=“name” scope=“page| request| session| application” beandetails/> class=“className” Class=“className” type=“typeName” Type=“typeName” Id---the case sensitive name used to identify the object instace. Scope—The scope within which the reference is available. The default value is page.

04/18/ JSP and JavaBeans Jsp:setProperty is used in conjunction with the useBean action described in the preceding section, and sets the value of simple and indexed properties in a bean. name--- The name of a bean instance defined by a tag property—The name of the bean property whose value is being set.

04/18/ JSP and JavaBeans jsp: getProperty --- is complementary to the jsp:setProperty action and is used to access the properties of a bean. It access the value of a property, converts it to a String, and prints it to the output stream. name--- The name of the bean instance from which the property is obtained. property--- The name of the property to retrieve.

04/18/ A example for using JavaBean An HTML form(which obtains input from the user to be processed by our JSP),SetProTest.html A example Enter word: Reverse SpellCheck

04/18/ A example for using JavaBean The main JSP file(wordpro1.jsp) You entered the input, The processed output is :

04/18/ A example for using JavaBean The bean(SpellCheck.java) /*** This bean encapsulatesthe functionality to spell check a string */ public class SpellCheck { private String word; public SpellCheck() {} /** * Method to reverse the string uses the reversed string */ public String reverse(){ return (new StringBuffer(word).reverse()).toString(); }

04/18/ /** * Check the spelling of the word. This method has ano body, and just * returns true for the example boolean, true if the spelling is right */ public boolean check(){ return true; } /** * Access method for the word property the current value of the word property */ public String getWord() { return word; } A example for using JavaBean The bean continue(SpellCheck.java)

04/18/ /** * Sets the value of the word property aWord the new value of the word property */ public void setWord(String aWord) { word = aWord; } A example for using JavaBean The bean continue(SpellCheck.java)

04/18/ What’s a session? A session can be defined as a series of related interactions between a single client and server, which take place over a period of time. JSP Session For example, consider a common three-step user interaction with a web site: 1.The user browses catalog on a web site, and chooses something from it to putting the shopping basket. 2. The user continues to use other tools and utilities on the site. 3.The user decides to complete the order selected in the first step.

04/18/ JSP Session Catalog Order Transfer the selected items to the order at some point during the session Time Order and pay for items HTTP connection Select items from catalog Browsing

04/18/ JSP Session Session Lifecycle It is created on the server as a result of a request and assigned a unique session ID and this ID is then passed to the client. The session itself, is however considered ‘new’ until the client return the session ID to the server indicating that a session has been established. This associated the client with that particular session object. A session exits on the server until it is invalidated(client logout, for example) or the server is stopped.

04/18/ A example of JSP Session The first page(p1.jsp) Please input your name:

04/18/ A example of JSP Session The second page(p2.jsp---1) <% name = request.getParameter("thename"); session.putValue("thename", name); %> Your name is:

04/18/ What's the topic you like ? A example of JSP Session The second page(p2.jsp—2)

04/18/ A example of JSP Session The third page(p3.page) <% topic = request.getParameter("topic"); String name = (String) session.getValue("thename"); %> Your name is : Your topic is:

04/18/ Two Basic Ways of Using JSP Technology The Page-Centric Approach This model allows JSPs or Servlets direct access to some resource like a database or legacy application to service a client’s request. The JSP page is where the incoming request is intercepted processed, and the response sent back to the client.

04/18/ Two Basic Ways of Using JSP Technology The Page-Centric Approach Page-View JSP Business Processing Request Response Page-View With Bean JSP Business Processing Bean Request Response

04/18/ Two Basic Ways of Using JSP Technology The Page-Centric Approach Advantage: It is simple to program, and allows the page author to generate dynamic content easily, based upon the request and the state of the resources. Disadvantage: l separation of presentation from content l not be suitable for complex implementation l Does not scale up well for a large number of simultaneous clients

04/18/ Two Basic Ways of Using JSP Technology The “Dispatcher” Approach(or “N-tiered” approach) A SERVLET( or JSP) acts as a mediator or controller, delegating requests to JSP pages and JavaBeans. The application is composed of multiple tiers, the JSP, interacts with the back end resource via another object or Enterprise JavaBeans component. The Enterprise JavaBeans server and the EJB provide managed access to resources, support transactions and access to underlying security mechanisms, thus addressing the resource sharing.

04/18/ Two Basic Ways of Using JSP Technology The Steps in “N-tiered” application design: Step1—identify the correct objects and their interaction. Step2—identify the JSPs and Servlets. These should be divided into two categories, depending on the role they play. ---Front end JSPs or Servlets that manage application flow and business logic evaluation. This is where a lot of method invocation on the objects, or usage of EJBs, can be coded. They are not responsible for any presentation, and act as a point to intercept the HTTP requests coming from users. ---Presentation JSPs that generate HTML or XML, with their main purpose in life being presentation of dynamic content. The figure below shows the relationship between these two categories.

04/18/ Two Basic Ways of Using JSP Technology The front-end component accepts a request, and then determines the appropriate presentation component to forward it to. The presentation component then processes the request and returns the response to another front component or directly back to the user. The “Dispatcher” Approach

04/18/ Final Words Some useful links t t t t t /com

04/18/ Thank you !