Glassfish, JAVA EE, Servlets, JSP, EJB. Software or ResourceVersion Required NetBeans IDE, Java bundle 6.9 6.8 or 6.9 Java Development Kit (JDK) 6 MySQL.

Slides:



Advertisements
Similar presentations
Customizing the MOSS 2007 Search Results November 2007 Rafael Perez.
Advertisements

1 Chapter 12 Working With Access 2000 on the Internet.
XP Browser and Basics1. XP Browser and Basics2 Learn about Web browser software and Web pages The Web is a collection of files that reside.
A Guide to Oracle9i1 Introduction To Forms Builder Chapter 5.
DT228/3 Web Development Databases. Database Almost all web application on the net access a database e.g. shopping sites, message boards, search engines.
Browser and Basics Tutorial 1. Learn about Web browser software and Web pages The Web is a collection of files that reside on computers, called.
Computer Science 101 Web Access to Databases Overview of Web Access to Databases.
ECE356 – Database Systems Lab 1 – Building a Web Project with NetBeans Tiuley Alguindigue Lab Instructor – University of Waterloo, E & CE Dept. Fall 2013.
CS 160: Software Engineering August 27 Class Meeting Department of Computer Science San Jose State University Fall 2014 Instructor: Ron Mak
1 Agenda Overview Review Roles Lists Libraries Columns.
Eclipse is an open source IDE (Integrated Development Environment) for developing applications in Java, C/C++, HTML, Cobol, Perl, etc. The official Eclipse.
Web Development & Design Foundations with XHTML Chapter 9 Key Concepts.
Chapter 10 Form Basics Key Concepts Copyright © 2013 Terry Ann Morris, Ed.D 1.
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.
8 Copyright © 2004, Oracle. All rights reserved. Creating LOVs and Editors.
M. Taimoor Khan * Java Server Pages (JSP) is a server-side programming technology that enables the creation of dynamic,
CSCI 6962: Server-side Design and Programming
Session 5: Working with MySQL iNET Academy Open Source Web Development.
Classroom User Training June 29, 2005 Presented by:
Server-side Scripting Powering the webs favourite services.
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.
Tutorial 10 Adding Spry Elements and Database Functionality Dreamweaver CS3 Tutorial 101.
® IBM Software Group © 2009 IBM Corporation Rational Publishing Engine RQM Multi Level Report Tutorial David Rennie, IBM Rational Services A/NZ
XP New Perspectives on Browser and Basics Tutorial 1 1 Browser and Basics Tutorial 1.
CIM6400 CTNW (04/05) 1 CIM6400 CTNW Lesson 6 – More on Windows 2000.
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.
CS441 CURRENT TOPICS IN PROGRAMMING LANGUAGES LECTURE 5_1 George Koutsogiannakis/ Summer
Creating a Web Site to Gather Data and Conduct Research.
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,
Tutorial 121 Creating a New Web Forms Page You will find that creating Web Forms is similar to creating traditional Windows applications in Visual Basic.
Web Server Administration Chapter 7 Installing and Testing a Programming Environment.
Just A Few More Fun Objectives 1 Having Some Fun With Java Script 2 Using Style Sheets.
Tutorial 7 Creating Forms. Objectives Session 7.1 – Create an HTML form – Insert fields for text – Add labels for form elements – Create radio buttons.
Domain 3 Understanding the Adobe Dreamweaver CS5 Interface.
Java Servlets example using NetBeans 6. Pre-requirements: Install Java JDK 1.6 Install NetBeans IDE 6 (we will use version NetBeans IDE update 16)
Lecturer: Prof. Piero Fraternali, Teaching Assistant: Alessandro Bozzon, Advanced Web Technologies: Struts–
Servlets Database Access. Agenda:  Setup Java Environment  Install Database  Install Database Drivers  Create Table and add records  Accessing a.
Chapter 8 Collecting Data with Forms. Chapter 8 Lessons Introduction 1.Plan and create a form 2.Edit and format a form 3.Work with form objects 4.Test.
Oracle 10g Database Administrator: Implementation and Administration Chapter 2 Tools and Architecture.
 Whether using paper forms or forms on the web, forms are used for gathering information. User enter information into designated areas, or fields. Forms.
Week 9 - Form Basics Key Concepts 1. 1.Describe common uses of forms on web pages 2.Create forms on web pages using the form, input, textarea, and select.
JDBC Tutorial CSCI 201L Jeffrey Miller, Ph.D. HTTP :// WWW - SCF. USC. EDU /~ CSCI 201 USC CSCI 201L.
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.
Oracle Data Integrator Agents. 8-2 Understanding Agents.
Chính phủ điện tử TS. Phạm Văn Tính Khoa CNTT, ĐH Nông Lâm TP.HCM
Evaluating & Maintaining a Site Domain 6. Conduct Technical Tests Dreamweaver provides many tools to assist in finalizing and testing your website for.
June 23, 2001Database Creation Review and Exercises1 Building an Application - Part I -
XP New Perspectives on Microsoft Office FrontPage 2003 Tutorial 7 1 Microsoft Office FrontPage 2003 Tutorial 8 – Integrating a Database with a FrontPage.
Creating a simple database This shows you how to set up a database using PHPMyAdmin (installed with WAMP)
CITA 310 Section 7 Installing and Testing a Programming Environment (Textbook Chapter 7)
Chapter 5 Introduction To Form Builder. Lesson A Objectives  Display Forms Builder forms in a Web browser  Use a data block form to view, insert, update,
Chapter 12© copyright Janson Industries Java Server Faces ▮ Explain the JSF framework ▮ SDO (service data objects) ▮ Facelets ▮ Pagecode classes.
T U T O R I A L  2009 Pearson Education, Inc. All rights reserved Address Book Application Introducing Database Programming.
10 Copyright © 2004, Oracle. All rights reserved. Building ADF View Components.
CHAPTER 7 LESSON C Creating Database Reports. Lesson C Objectives  Display image data in a report  Manually create queries and data links  Create summary.
IE 411/511: Visual Programming for Industrial Applications Lecture Notes #2 Introduction to the Visual Basic Express 2010 Integrated Development Environment.
Plug-In Architecture Pattern. Problem The functionality of a system needs to be extended after the software is shipped The set of possible post-shipment.
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.
MYSQL AND MYSQL WORKBENCH MIS2502 Data Analytics.
Settings MySQL Database and JDBC configuration Instructor: Sergey Goldman.
Software-Projekt 2008 Seminarvortrag“Short tutorial of MySql“ Wei Chen Verena Honsel.
Joomla Awdhesh Kumar Singsys Pte Ltd. What is Joomla? Joomla is an award-winning content management system (CMS), which enables you to build Web sites.
XP Creating Web Pages with Microsoft Office
C Copyright © 2009, Oracle. All rights reserved. Using SQL Developer.
COM621: Advanced Interactive Web Development Lecture 10 PHP and MySQL.
Labs: Create, deploy and test a simple web service
Presentation transcript:

Glassfish, JAVA EE, Servlets, JSP, EJB

Software or ResourceVersion Required NetBeans IDE, Java bundle or 6.9 Java Development Kit (JDK) 6 MySQL database server 5.1 MySQL Connector/J JDBC Driver 5.x version 5.x GlassFish server v3 or Open Source Edition Java platforms MySQL database protocol necessary for communication between Java platforms and the MySQL database protocol (already included inside of NetBeans)

index.jsp JSTL code The welcome page (index.jsp) presents the user with a simple HTML form. When a browser requests index.jsp, the JSTL code within the page initiates a query on MyNewDatabase. Subject database table It retrieves data from the Subject database table, and inserts it into to the page before it is sent to the browser. Table TWO-TIER Architecture: a Java web application communicates directly with a MySQL database using the Java Database

(Sample Run) Final Project Submit Subject selected Index.jsp Response.jsp

This example requires that the (username) root’s password is not empty.

mysqld --init-file mysql-init.txt C:\Program Files (x86)\EasyPHP-5.3.3\mysql\bin> mysqld --init-file =c:\\mysql-init.txt Resetting the root password Create a password file: --init-file Start the MySQL server with the special --init-file option (notice that the backslash in the option value is doubled): nbuser root UPDATE mysql.user SET Password=PASSWORD(‘ nbuser ') WHERE User='root'; FLUSH PRIVILEGES; mysql-init.txt Save the file. For this example, the file will be named C:\ mysql-init.txt. New password

select FROM mysql> select user, host, password FROM mysql.user; Displaying existing accounts Encrypted passwords You can verify if you succeeded in changing the root password by issuing the Following mysql command:

File/New Project/Java Web/Web Application From the menu, select File/New Project/Java Web/Web Application Create a New Project International Former Professional Wrestlers’ Association for Counseling and Development

Create a New Project web.xml We want to see how to create a deployment descriptor (web.xml), that’s Java EE 5 why we want to select Java EE 5

Result: Welcome Page (index.jsp) We can easily add a table here using a Palette. Add Table and Form here comment JSP Page directive

Invoke the Palette Window From the menu, select Window/Palette You can also configure the display of the Palette by right-clicking the Palette title bar, and selecting Show Big Icons. This is the result of changing the display into using Big icons This toggles between Show Big and Small icons

Add a Table using the Palette tag Position the cursor at your target coordinates (after the tag), then Table Insert a Table by double-clicking the icon for Table

Add a Form using the Palette and tags Position the cursor at your target coordinates (in between the and tags), then Insert a Form by double-clicking the icon for Forms

Welcome to IFPWAFCAD, the International Former Professional Wrestlers' Association for Counseling and Development! IFPWAFCAD offers expert counseling in a wide range of fields. To view the contact details of an IFPWAFCAD certified former professional wrestler in your area, select a subject below: response.jsp Select a subject: Select a subject: Edit Index.jsp

Add a Drop-Down List using the Auto-completion support (Ctrl+Space) Ctrl+Space Press Ctrl+Space to invoke the Auto-completion support

Add a submit button Add a submit button item to a point just after the drop-down list you just added.

Run your index.jsp file To view this page in a browser, right-click in the editor and choose Run File (Shift-F6). When you do this, the JSP page is automatically compiled and deployed to your server. The IDE opens your default browser to display the page from its deployed location. CSS formatting. At this stage the web page doesn’t look nice yet.. We can format this later using CSS formatting.

Creating the response page projectNew / JSP Right-click the project, then select New / JSP.

{placeholder} {placeholder} Description: Description: {placeholder} {placeholder} Counselor: Counselor: {placeholder} member since:{placeholder} member since: {placeholder} Contact Details: Contact Details: mailto:{placeholder}{placeholder} {placeholder} phone:{placeholder} phone: {placeholder} Insert the following table into the response page

Execute the response page Run File To view this page in a browser, right-click in the editor and choose Run File (Shift-F6).

Add CSS

body { font-family: Verdana, Arial, sans-serif; font-size: smaller; padding: 50px; color: #555; } h1 { text-align: left; letter-spacing: 6px; font-size: 1.4em; color: #be7429; font-weight: normal; width: 450px; } table { width: 580px; padding: 10px; background-color: #c5e7e0; } th { text-align: left; border-bottom: 1px solid; } td { padding: 10px; } a:link { color: #be7429; font-weight: normal; text-decoration: none; } a:link:hover { color: #be7429; font-weight: normal; text-decoration: underline; } Add CSS

style.css... Add CSS index.jsp response.jsp. Add a link to your style.css file in both index.jsp and response.jsp. section put the link in the section

Display Result: index.jsp (with CSS) CSS-style Look at the effect of applying the CSS-style to index.jsp

Display Result: response.jsp (with CSS)

nbuser This tutorial uses nbuser as an example password. To set your password to nbuser, navigate to your MySQL installation's bin directory in the command-line prompt and enter the following: shell> mysql -u root nbuser mysql> UPDATE mysql.user SET Password = PASSWORD('nbuser') root -> WHERE User = 'root'; mysql> FLUSH PRIVILEGES; Changing the root password

Connecting to a MySQL Database Default port number of MySQL server Services windowDatabases nodeMySQL Server node In the Services window, expand the Databases node, right-click the MySQL Server node and choose Properties. nbuser Enter password: nbuser

Connecting to a MySQL Database

Creating and Connecting to a MySQL Database Instance

Creating a Table using the Database Explorer SQL file This is optional if you have an SQL file containing the entire database structure. You can simply load it later.

Add an Existing SQL Script File/Open/Load SQL file Select the database to connect to

Our newly added database

Database Structure

Setting up a JDBC data source and connection pool

Create a new one Java Naming and Directory Interface Java Naming and Directory Interface (JNDI)naming system Java Naming and Directory Interface (JNDI) – a naming system is required to manage the lookup between names and resources (e.g. Database).

The database that we want to connect to

Sun-resources.xml Sun-resources.xml will be created automatically. This will contain entries for the data source and connection pool that you have specified. The new password should reflect here

IFPWAFCADDEPLOY Right-click the IFPWAFCAD project node, then select DEPLOY Open the Services window, and expand the Servers/Glassfish/Resources/JDBC/JDBC Resources and Connection Pools nodes

reference JDBC resource You need to reference the JDBC resource you just configured from the web application

Deployment descriptors XML-based how an application is to be deployed to a specific environment. Deployment descriptors are XML-based text files that contain information describing how an application is to be deployed to a specific environment. For example, they are normally used to specify: application context parameters and behavioural patterns security settings mappings for servlets, filters and listeners. Deployment Descriptor: Web.xml

Projects Window Projects Window/ Configuration Files folder/ open web.xml Web.xml

Select the References tab, click on the Add button, then enter details reference data source We need to reference the data source in the application’s deployment descriptor. Web.xml

Verifying the Results of adding the Resource Reference Web.xml

We need to add the database driver’s JAR file to enable the server to communicate with our database.

From the menu, select the Tools, Servers.

Select Glassfish, then enable the JDBC driver deployment option instance You are actually connecting to an instance of the Glassfish application server. Each instance runs in a unique domain, and the driver should be located within the domain (e.g. domain1)

We could verify that our database driver has been installed properly by inspecting the actual directory of the domain.

We can generate content for the JSP placeholders that we’ve created by implementing JSTL codes. JSTL technology performs the logic that directly queries the database and inserts the retrieved data into the two pages

JSTL allows us to access and display data taken from the database. Glassfish server includes the JSTL library by default. JavaServer Pages Standard Tag Library (JSTL)

We need to populate the form inside index.jsp with names coming from the Subject database table. From the Palette, select the DB Report icon. Insert here

Specify the data source and variable name for the DB Report to create query to create query to loop through the query’s results set and output the retrieved data to loop through the query’s results set and output the retrieved data JSTL Tags jdbc/IFPWAFCAD

Automatically Generated Codes (index.jsp) directives required for the sql and forEach tags. Custom tags

SELECT subject_id, name FROM Subject <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" " IFPWAFCAD Homepage Welcome to IFPWAFCAD, the International Former Professional Wrestlers' Association for Counseling and Development! IFPWAFCAD offers expert counseling in a wide range of fields. To view the contact details of an IFPWAFCAD certified former professional wrestler in your area, select a subject below: Select a subject: (index.jsp) Form SQL Query Table CSS html Custom tags

The file is: deployed deployed to the GlassFish server, compiled into a servlet compiled into a servlet, and then renders renders in your default browser. DB Report The code generated from the DB Report item creates the following table in the welcome page. Runindex.jsp Run the welcome page (index.jsp) to see how it displays in a browser.

(Sample Run) The Project, so far... 1.Change root password to nbuser 2.Start EasyPHP to start phpMyAdmin and MySQL server. 3.Stop Apache. Remember, we are using Glassfish this time. 4.Run NetBeans, run the web application How to run your web application? Netbeans Glassfish Java EE application server EasyPHP MySQL server phpMyAdmin Apache web server

(Sample Run) The Project, so far... Next, we would like to put these generated HTML codes into the drop-down list

Select a subject: ${row.name} subject_id HTML tags the tags loop through all subject_id and name values from the SQL query, and insert each pair into the HTML tags. In this manner, the form's drop-down list is populated with data. Integrate the tags into the HTML form as follows. (index.jsp)

(Sample Run) The Project, so far... Subject chosen

DB Query component Insert a DB Query component on top of tag

Customise the query as indicated below.

Automatically generated code (response.jsp) The IDE automatically added the directive needed for the tag drop-down list index.jsp Extracts the user’s choice from the drop-down list of index.jsp

<c:set variable tag Add a <c:set variable tag to store the first record returned by the query. (response.jsp) Added lines directive Add a directive to allow us to use the <c:set tag.

${counselorDetails.name} ${counselorDetails.name} Description: ${counselorDetails.description} Counselor: ${counselorDetails.first_name} ${counselorDetails.nick_name} ${counselorDetails.last_name} ${counselorDetails.member_since} member since: ${counselorDetails.member_since} Contact Details: ${counselorDetails. } ${counselorDetails. } ${counselorDetails.telephone} phone: ${counselorDetails.telephone} {placeholders}Expression Language (blue highlights) Replace the {placeholders} with the following Expression Language (EL) statements (blue highlights) (response.jsp) Run the application!

(Sample Run) Final Project Submit Subject selected Index.jsp Response.jsp

JSTL – for dynamic logic Jsf-impl.jar – required library to utilise JSTL codes Jdbc/IFPWAFCAD – name of data resource JSP documents MySQL server, database with 2 tables Glassfish Java EE application server

Web browser submit Glassfish Java EE application server JSTL codes Index.jsp Jsf-impl.jar Server-Client Interaction Project Name: IFPWAFCAD subject_id Name: subject_id submit Name: submit 0. JSP is deployed to the server and compiled into a servlet

Web browser submit Glassfish Java EE application server JSTL codes Index.jsp Jsf-impl.jar MySQL Server Subject (Table) Counselor(Table) MyNewDatabase Server-Client Interaction Data resource: Name: jdbc/IFPWAFCAD Project Name: IFPWAFCAD subject_id Name: subject_id submit Name: submit We would like to populate the drop-down list with records coming from MyNewDatabase, Subject table.

Web browser submit Glassfish Java EE application server JSTL codes Index.jsp Jsf-impl.jar MySQL Server Subject (Table) Counselor(Table) MyNewDatabase Server-Client Interaction Project Name: IFPWAFCAD 1. Request for index.jsp subject_id Name: subject_id submit Name: submit

Web browser submit Glassfish Java EE application server JSTL codes Index.jsp Jsf-impl.jar MySQL Server Subject (Table) Counselor(Table) MyNewDatabase Server-Client Interaction 1. Request for index.jsp 2. Initiate query on subject table Data resource: Name: jdbc/IFPWAFCAD

Web browser submit Glassfish Java EE application server JSTL codes Index.jsp Jsf-impl.jar MySQL Server Subject (Table) Counselor(Table) MyNewDatabase Server-Client Interaction Data resource: Name: jdbc/IFPWAFCAD 3. Send records based on query result Insert records into page by referring to the name of data source 2. Initiate query on subject table

Web browser submit Glassfish Java EE application server JSTL codes Index.jsp Jsf-impl.jar MySQL Server Subject (Table) Counselor(Table) MyNewDatabase Server-Client Interaction Data resource: Name: jdbc/IFPWAFCAD Insert records into page by referring to the name of data source 5. Send generated page back to browser via HTTP

Database Connection

Project JSP files: index.jsp, response.jsp Configuration files: web.xml Services Jdbc:mysql://localhost:3306 Databases mynewdatabase Server: Glassfish Server 3 Mysql-connector-java bin.jar Domain1 Enable JDBC driver deployment  DATA resource New jdbc connection pool: IFpwafcadPool Jdbc resource: jdbc/IFPWAFCAD Jndi name: jdbc/IFPWAFCAD Sun-resources.xml Web.xml Deployment Descriptor Database Driver Must reside inside the server’s directory

Project JSP files: index.jsp, response.jsp Configuration files: web.xml Services Jdbc:mysql://localhost:3306 Databases mynewdatabase Server: Glassfish Server 3 Mysql-connector-java bin.jar Domain1 Enable JDBC driver deployment  DATA resource New jdbc connection pool: IFpwafcadPool Jdbc resource: jdbc/IFPWAFCAD Jndi name: jdbc/IFPWAFCAD Sun-resources.xml Web.xml Deployment Descriptor Database Driver Both data source and connection pool need to be registered with Glassfish server Must reside inside the server’s directory

Project JSP files: index.jsp, response.jsp Configuration files: web.xml Services Jdbc:mysql://localhost:3306 Databases mynewdatabase Server: Glassfish Server 3 Mysql-connector-java bin.jar Domain1 Enable JDBC driver deployment  DATA resource New jdbc connection pool: IFpwafcadPool Jdbc resource: jdbc/IFPWAFCAD Jndi name: jdbc/IFPWAFCAD Sun-resources.xml Web.xml Deployment Descriptor Database Driver Contains a reference to the data source Both data source and connection pool need to be registered with Glassfish server Must reside inside the server’s directory

Project JSP files: index.jsp, response.jsp Configuration files: web.xml Services Jdbc:mysql://localhost:3306 Databases mynewdatabase Server: Glassfish Server 3 Mysql-connector-java bin.jar Domain1 Enable JDBC driver deployment  DATA resource New jdbc connection pool: IFpwafcadPool Jdbc resource: jdbc/IFPWAFCAD Jndi name: jdbc/IFPWAFCAD Sun-resources.xml Web.xml Deployment Descriptor Database Driver Contains a reference to the data source Both data source and connection pool need to be registered with Glassfish server Must reside inside the server’s directory