Java Server Pages A JSP page is a text-based document that contains two types of text: static template data, which can be expressed in any text-based format,

Slides:



Advertisements
Similar presentations
A plataforma J2EE.
Advertisements

JSP and web applications
Integrating Access with the Web and with Other Programs.
A Guide to Oracle9i1 Introduction To Forms Builder Chapter 5.
JSP Java Server Pages Reference:
Outline IS400: Development of Business Applications on the Internet Fall 2004 Instructor: Dr. Boris Jukic Server Side Web Technologies: Part 2.
1 Build a Web Application on J2EE. 2 J2EE Scenario Client – Web Server – EIS Resources Client – Web Server – EIS Resources Client – Application Server.
Java Server Pages B.Ramamurthy. Java Server Pages Servlets are pure Java programs. They introduce dynamism into web pages by using programmatic content.
1 Java Server Pages Can web pages be created specially for each user? What part does Java play?
Create a New Application and Project Open the Create Application dialog. Enter the application name of your choice and the directory. Select No Template.
Figure 1. Hit analysis in 2002 of database-driven web applications Hits by Category in 2002 N = 73,873 Results Reporting 27% GME 26% Research 20% Bed Availability.
Web Applications Basics. Introduction to Web Web features Clent/Server HTTP HyperText Markup Language URL addresses Web server - a computer program that.
ECE356 – Database Systems Lab 1 – Building a Web Project with NetBeans Tiuley Alguindigue Lab Instructor – University of Waterloo, E & CE Dept. Fall 2013.
Java Enterprise Edition Java Web Development Structure of a web project Introduction to Web Applications The first project Introduction to Java Web Development.
Access Tutorial 8 Sharing, Integrating, and Analyzing Data
Eclipse is an open source IDE (Integrated Development Environment) for developing applications in Java, C/C++, HTML, Cobol, Perl, etc. The official Eclipse.
1 ADVANCED MICROSOFT WORD Lesson 15 – Creating Forms and Working with Web Documents Microsoft Office 2003: Advanced.
Java Server Pages B.Ramamurthy. Topics for Discussion 8/20/20152 Inheritance and Polymorphism Develop an example for inheritance and polymorphism JSP.
DAT602 Database Application Development Lecture 15 Java Server Pages Part 1.
Chapter 10 EJB Concepts of EJB Three Components in Creating an EJB Starting/Stopping J2EE Server and Deployment Tool Installation and Configuration of.
M. Taimoor Khan * Java Server Pages (JSP) is a server-side programming technology that enables the creation of dynamic,
Distributed Multitiered Applications The J2EE platform uses a multitiered distributed application model. Application logic is divided into components 1.
Chapter 16 The World Wide Web Chapter Goals Compare and contrast the Internet and the World Wide Web Describe general Web processing Describe several.
4-Tier Model Client Tier Web Tier Business Tier EIS Tier.
Chapter 16 The World Wide Web. 2 The Web An infrastructure of information combined and the network software used to access it Web page A document that.
Servlets and JSPs We will start in this session a detail discussion of using Servlets and JSPs to deliver web services for creating dynamic contents. However,
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.
10 Adding Interactivity to a Web Site Section 10.1 Define scripting Summarize interactivity design guidelines Identify scripting languages Compare common.
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.
 Embeds Java code  In HTML tags  When used well  Simple way to generate dynamic web-pages  When misused (complex embedded Java)  Terribly messy.
J2EE Structure & Definitions Catie Welsh CSE 432
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.
Lecturer: Prof. Piero Fraternali, Teaching Assistant: Alessandro Bozzon, Advanced Web Technologies: Struts–
JAVA SERVER PAGES CREATING DYNAMIC WEB PAGES USING JAVA James Faeldon CS 119 Enterprise Systems Programming.
J2EE Overview Web Programming CSCI J2EE multi-tier architecture Servlet: Java class loaded into Web server JSP page: enhanced HTML page that is.
© Copyright by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. 1 Outline 32.1 Reviewing the Bookstore Application 32.2.
How to Build a Struts Application with JBuilder 9.
Writing Enterprise Applications with J2EE (Fourth lesson) Alessio Bechini June 2002 (based on material by Monica Pawlan)
JSP Fundamentals Elements of a JSP Using Beans with JSP Integrating Servlets and JSP.
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.
© Copyright by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. 1 Outline 31.1 Reviewing the Bookstore Application 31.2.
A seminar on j2ee by saritha. s. What is J2EE J2EE (Java 2 Platform, Enterprise Edition) is a Java platform designed for the mainframe-scale computing.
XP New Perspectives on Microsoft Office FrontPage 2003 Tutorial 7 1 Microsoft Office FrontPage 2003 Tutorial 8 – Integrating a Database with a FrontPage.
JSP BASICS AND ARCHITECTURE. Goals of JSP Simplify Creation of dynamic pages. Separate Dynamic and Static content.
Entity Beans & Persistence Chris Alexander CS 486 Spring 2001.
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.
COMP9321 Web Application Engineering Semester 2, 2015 Dr. Amin Beheshti Service Oriented Computing Group, CSE, UNSW Australia Week 3 1COMP9321, 15s2, Week.
Chapter 12© copyright Janson Industries Java Server Faces ▮ Explain the JSF framework ▮ SDO (service data objects) ▮ Facelets ▮ Pagecode classes.
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.
XP New Perspectives on Microsoft Office Access 2003, Second Edition- Tutorial 8 1 Microsoft Office Access 2003 Tutorial 8 – Integrating Access with the.
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.
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.
17 Copyright © 2004, Oracle. All rights reserved. Integrating J2EE Components.
Spell Checker web service (you build a web client that interacts with the service) The client uses a servlet class and a JSP page. The user passes information.
Section 10.1 Define scripting
Running a Forms Developer Application
J2EE Application Development
Understanding and Designing with EJB
Access Tutorial 8 Sharing, Integrating, and Analyzing Data
Microsoft Office Access 2003
Java Server Pages B.Ramamurthy.
Microsoft Office Access 2003
Understanding and Designing with EJB
Enterprise Java Beans.
Tutorial 8 Sharing, Integrating, and Analyzing Data
Presentation transcript:

Java Server Pages A JSP page is a text-based document that contains two types of text: static template data, which can be expressed in any text-based format, such as HTML, SVG, WML, and XML; and JSP elements, which construct dynamic content.HTMLSVGWMLXML; A syntax card and reference for the JSP elements are available at:

Your First JSP Page The Web page in Figure 11-1 is a form that allows you to select a locale and displays the date in a manner appropriate to the locale.Figure 11-1 Figure 11-1 Localized Date Form The source code for this example is in the j2eetutorial/examples/src/web/date directory created when you unzip the tutorial bundle. The JSP page index.jsp used to create the form appears below; it is a typical mixture of static HTML markup and JSP elements. If you have developed Web pages, you are probably familiar with the HTML document structure statements (,, and so on) and the HTML statements that create a form ( ) and a menu ( ).index.jsp

The source code briefing The source code for this example is in the j2eetutorial/examples/src/web/date directory created when you unzip the tutorial bundle. The JSP page index.jsp used to create the form appears below; it is a typical mixture of static HTML markup and JSP elements. If you have developed Web pages, you are probably familiar with the HTML document structure statements (,, and so on) and the HTML statements that create a form ( ) and a menu ( ). The lines in bold in the example code contain the following types of JSP constructs: index.jsp  Directives ( ) import classes in the java.util package and the MyLocales class, and set the content type returned by the page.  The jsp:useBean element creates an object containing a collection of locales and initializes a variable that points to that object.  Scriptlets ( ) retrieve the value of the locale request parameter, iterate over a collection of locale names, and conditionally insert HTML text into the output.  Expressions ( ) insert the value of the locale name into the response.  The jsp:include element sends a request to another page (date.jsp) and includes the response in the response from the calling page.

The code listing Localized Dates <jsp:useBean id="locales" scope="application" class="MyLocales"/> Locale: <% String selectedLocale = request.getParameter("locale"); Iterator i = locales.getLocaleNames().iterator(); while (i.hasNext()) { String locale = (String)i.next(); if (selectedLocale != null && selectedLocale.equals(locale)) { %> <% } else { %> <% } %>

How to build, deploy, and execute this JSP page? 1/2  Go to j2eetutorial/examples and build the example by executing ant date (see How to Build and Run the Examples).How to Build and Run the Examples  Create a J2EE application called DateApp. Select FileNewApplication. In the file chooser, navigate to j2eetutorial/examples/src/web/date. In the File Name field, enter DateApp. Click New Application. Click OK.  Create the WAR and add the Web components to the DateApp application. Select FileNewWeb Component. Select DateApp from the Create New WAR File In Application combo box. Enter DateWAR in the WAR Display Name field. Click Edit. Navigate to j2eetutorial/examples/build/web/date. Select index.jsp, date.jsp, MyDate.class, and MyLocales.class and click Add. Then click Finish. Click Next. Click JSP In The Web Component radio button, and then click Next. Select index.jsp from the JSP Filename combo box. Click Finish. (Continue on next slide…)

How to build, deploy, and execute this JSP page? 2/2  Enter the context root. Select DateApp. Select the Web Context tab. Enter date.  Deploy the application. Select ToolsDeploy. Click Finish.  Invoke the URL :8000/date in a browser. You will see a combo box whose entries are locales. Select a locale and click Get Date. You will see the date expressed in a manner appropriate for that locale.

Another Example of JSP pages (Duke Bookstore) To illustrate JSP technology, this chapter rewrites each servlet in the Duke's Bookstore application introduced in The Example Servlets in as a JSP page. Table 11-1 lists the functions and their corresponding JSP pages.The Example ServletsTable 11-1 Table 11-1 Duke's Bookstore Example JSP Pages FunctionJSP Pages Enter the bookstore bookstore.jsp Create the bookstore banner banner.jsp Browse the books offered for sale catalog.jsp Put a book in a shopping cart catalog.jsp and bookdetails.jsp Get detailed information on a specific book bookdetails.jsp Display the shopping cart showcart.jsp Remove one or more books from the shopping cart showcart.jsp Buy the books in the shopping cart cashier.jsp Receive an acknowledgement for the purchase receipt.jsp

Code Analysis The data for the bookstore application is still maintained in a database. However, two changes are made to the database helper object database.BookDB.database.BookDB The database helper object is rewritten to conform to JavaBeans component design patterns as described in JavaBeans Component Design Conventions (page 270). This change is made so that JSP pages can access the helper object using JSP language elements specific to JavaBeans components. Instead of accessing the bookstore database directly, the helper object goes through an enterprise bean. The advantage of using an enterprise bean is that the helper object is no longer responsible for connecting to the database; this job is taken over by the enterprise bean. Furthermore, because the EJB container maintains the pool of database connections, an enterprise bean can get a connection quicker than the helper object can. The relevant interfaces and classes for the enterprise bean are the database.BookDBEJBHome home interface, database.BookDBEJB remote interface, and the database.BookDBEJBImpl implementation class, which contains all the JDBC calls to the database. The implementation of the database helper object follows. The bean has two instance variables: the current book and a reference to the database enterprise bean.

Code Analysis public class BookDB { private String bookId = "0"; private BookDBEJB database = null; public BookDB () throws Exception { } public void setBookId(String bookId) { this.bookId = bookId; } public void setDatabase(BookDBEJB database) { this.database = database; } public BookDetails getBookDetails() throws Exception { try { return (BookDetails)database. getBookDetails(bookId); } catch (BookNotFoundException ex) { throw ex; }... } Finally, this version of the example contains an applet to generate a dynamic digital clock in the banner. See Including an Applet for a description of the JSP element that generates HTML for downloading the applet.Including an Applet The source code for the application is located in the j2eetutorial/examples/src/web/bookstore2 directory created when you unzip the tutorial bundle (see Downloading the Examples).Downloading the Examples

How to build, deploy, and run the example: 1/2 1. Go to j2eetutorial/examples and build the example by running ant bookstore2. 2. Start the j2ee server. 3. Start deploytool. 4. Start the Cloudscape database by executing cloudscape -start. 5. If you have not already created the bookstore database, run ant create-web-db. 6. Create a J2EE application called Bookstore2App. a. Select FileNewApplication. b. In the file chooser, navigate to j2eetutorial/examples/src/web/bookstore2. c. In the File Name field, enter Bookstore2App. d. Click New Application. e. Click OK. 7. Add the Bookstore2WAR WAR to the Bookstore2App application. a. Select FileAddWeb WAR. b. In the Add Web WAR dialog box, navigate to j2eetutorial/examples/build/web/bookstore2. Select bookstore2.war. Click Add Web WAR. 8. Add the BookDBEJB enterprise bean to the application. a. Select FileNew Enterprise Bean. b. Select Bookstore2App from the Create New JAR File In Application combo box. c. Type BookDBJAR in the JAR Display Name field. d. Click Edit to add the content files. e. In the Edit Archive Contents dialog box, navigate to the j2eetutorial/examples/build/web/ejb directory and add the database and exception packages. Click Next. f. Choose Session and Stateless for the Bean Type. g. Select database.BookDBEJBImpl for Enterprise Bean Class. h. In the Remote Interfaces box, select database.BookDBEJBHome for Remote Home Interface and database.BookDBEJB for Remote Interface. i. Enter BookDBEJB for Enterprise Bean Name. j. Click Next and then click Finish.

How to build, deploy, and run the example: 2/2 9. Add a resource reference for the Cloudscape database to the BookDBEJB bean. a. Select the BookDBEJB enterprise bean. b. Select the Resource Refs tab. c. Click Add. d. Select javax.sql.DataSource from the Type column. e. Enter jdbc/BookDB in the Coded Name field. 10. Save BookDBJAR. a. Select BookDBJAR. b. Select File Save As. c. Navigate to the directory examples/build/web/ejb. d. Enter bookDB.jar in the File Name field. e. Click Save EJB JAR As. 11. Add a reference to the enterprise bean BookDBEJB. a. Select Bookstore2WAR. b. Select the EJB Refs tab. c. Click Add. d. Enter ejb/BookDBEJB in the Coded Name column. e. Select Session in the Type column. f. Select Remote in the Interfaces column. g. Enter database.BookDBEJBHome in the Home Interface column. h. Enter database.BookDBEJB in the Local/Remote Interface column. 12. Specify the JNDI Names. a. Select Bookstore2App. b. In the Application table, locate the EJB component and enter BookDBEJB in the JNDI Name column. c. In the References table, locate the EJB Ref and enter BookDBEJB in the JNDI Name column. d. In the References table, locate the Resource component and enter jdbc/Cloudscape in the JNDI Name column. 13. Enter the context root. a. Select the Web Context tab. b. Enter bookstore Deploy the application. a. Select Tools Deploy. b. Click Finish. 15. Open the bookstore URL :8000/bookstore2/enter.

Result