Multimedia and Advance Web Technologies
By:
Dr. Mohammad Shoab
Week 7, 8 & 9
Java platform
A Java platform comprises the JVM together with supporting class libraries.
Java 2 Standard Edition (J2SE)
Java 2 Platform, Enterprise Edition (J2EE)
Java Platform, Enterprise Edition (Java EE)
2
Multimedia and Advance Web Technologies
Department of Computer Science
Java platform
Java Micro Edition (Java ME)
3
Multimedia and Advance Web Technologies
Department of Computer Science
4
What is a
Java Web application?
Multimedia and Advance Web Technologies
Department of Computer Science
Java Web Application
A Java web application generates interactive web pages containing various types of markup language (HTML, XML, and so on) and dynamic content.
It is typically comprised of web components such as:
to modify and temporarily store data, interact with databases and web services, and render content in response to client requests.
5
Multimedia and Advance Web Technologies
Department of Computer Science
6
What is the
Java Enterprise Edition?
Multimedia and Advance Web Technologies
Department of Computer Science
Java EE (Enterprise Edition)
Java EE (Enterprise Edition) is a widely used platform containing a set of coordinated technologies that significantly reduce the cost and complexity of:
multitier, server-centric applications.
Java EE builds upon the Java SE platform and provides a set of APIs (application programming interfaces) for developing and running portable, robust, scalable, reliable and secure server-side applications.
Java EE 6 is supported only by the GlassFish server v3.x.
7
Multimedia and Advance Web Technologies
Department of Computer Science
Java EE 6 Platform
8
Multimedia and Advance Web Technologies
Department of Computer Science
Java EE application model
9
Multimedia and Advance Web Technologies
Department of Computer Science
10
What is a
Java Servlet?
Multimedia and Advance Web Technologies
Department of Computer Science
Java Servlets
11
Multimedia and Advance Web Technologies
Department of Computer Science
How do Servlets work?
12
Multimedia and Advance Web Technologies
Department of Computer Science
13
What is a
Java EE Container?
Multimedia and Advance Web Technologies
Department of Computer Science
Java EE Containers
Java EE containers
The Java EE platform uses "containers" to simplify development.
14
Multimedia and Advance Web Technologies
Department of Computer Science
Java EE Containers
When a request comes in:
* All of the above are the tasks of the web container.
15
Multimedia and Advance Web Technologies
Department of Computer Science
Java EE Containers
Java EE SERVER
From Bodoff et. al. 2005
16
Figure: JEE Containers diagram
Multimedia and Advance Web Technologies
Department of Computer Science
Historically (Java Web App) �Server: response
17
Client
Web browser
Operating
System
Web server
Servlet
(Java code)
Server
Operating System
Internet
Web Container Application
(Java code)
HTTP
TCP/IP
GET...
GET...
It’s the Container that gives
the Servlet the HTTP request
and response, and it’s the Container that calls the Servlet’s methods (e.g. doPost() or doGet())
<html>
<head>
</head>
<body>
...
<body>
</html>
<html>
<head>
</head>
<body>
...
<body>
</html>
Multimedia and Advance Web Technologies
Department of Computer Science
Historically (Java Web App) �Server: response
18
Client
Web browser
Operating
System
Web server
Servlet
(Java code)
Server
Operating System
Internet
HTTP
TCP/IP
GET...
GET...
It’s the Container that gives
the Servlet the HTTP request
and response, and it’s the Container that calls the Servlet’s methods (e.g. doPost() or doGet())
<html>
<head>
</head>
<body>
...
<body>
</html>
<html>
<head>
</head>
<body>
...
<body>
</html>
Multimedia and Advance Web Technologies
Department of Computer Science
(Java Web App) Server: response
19
Client
Web browser
Operating
System
Web server + Container
Servlet
(Java code)
Server
Operating System
Internet
HTTP
TCP/IP
GET...
It’s the Container that gives
the Servlet the HTTP request
and response, and it’s the Container that calls the Servlet’s methods (e.g. doPost() or doGet())
<html>
<head>
</head>
<body>
...
<body>
</html>
Grizzly is now the HTTP front end of the application server
Multimedia and Advance Web Technologies
Department of Computer Science
Java Servlets
Java Servlets simplify web development by providing infrastructure for component, communication, and session management in a web container that is integrated with a web server.
20
Multimedia and Advance Web Technologies
Department of Computer Science
JavaBeans
Client/Database | Server |
application client or applet | components running on the Java EE server |
database | Server components |
21
Multimedia and Advance Web Technologies
Department of Computer Science
Enterprise JavaBeans (EJB)
Enterprise JavaBeans container handles:
has a new packaging! (see figure)
New EJB 3.1 Packaging
Older EJB Packaging
22
Multimedia and Advance Web Technologies
Department of Computer Science
23
Netbeans IDE
Multimedia and Advance Web Technologies
Department of Computer Science
NetBeans
Class libraries for Servlets, JSPs, Enterprise Java Beans, advanced XML
24
Multimedia and Advance Web Technologies
Department of Computer Science
25
Example: NetBeans Project
A Quick Tour of the IDE (v.6.9)
JSP, Java Bean, User-defined Java Class & Package, Get Method, User Interface
Multimedia and Advance Web Technologies
Department of Computer Science
26
Sample Project
Index.jsp
NameHandler.java
Main interface, Html with form
Invokes response.jsp through form action.
response.jsp
Class NameHandler containing user data
Generates the server’s response
Defines a JavaBean to connect the class NameHandler to
the user’s input via a form text field (name).
Multimedia and Advance Web Technologies
Department of Computer Science
Creating a new Web Application
New Project / Java Web
27
Multimedia and Advance Web Technologies
Department of Computer Science
Creating a new Web Application
Specify Project Name
28
Multimedia and Advance Web Technologies
Department of Computer Science
Creating a new Web Application
GlassFish Server
Web profile
29
Multimedia and Advance Web Technologies
Department of Computer Science
Java Application Server: Glassfish
GlassFish
is an open source application server project led by Sun Microsystems for the Java EE platform. The proprietary version is called Oracle GlassFish Enterprise Server. GlassFish is free software
It uses a derivative of Apache Tomcat as the servlet container for serving Web content, with an added component called Grizzly which uses Java NIO for scalability and speed.
Before the advent of the Java New I/O API (NIO), thread management issues made it impossible for a server to scale to thousands of users
Sun is the original creator of Tomcat
30
Multimedia and Advance Web Technologies
Department of Computer Science
Java Application Server: Glassfish
GlassFish is an open source (full) application server project led by Sun Microsystems for the Java EE platform. The proprietary version is called Oracle GlassFish Enterprise Server. GlassFish is free software.
It uses a derivative of Apache Tomcat as the servlet container for serving Web content, with an added component called Grizzly which uses Java NIO for scalability and speed.
On 25 March 2010, soon after the acquisition of Sun Microsystems, Oracle issued a Roadmap for versions 3.0.1, 3.1, 3.2 and 4.0 with themes revolving around clustering, virtualization and integration with Coherence and other Oracle technologies.
31
Multimedia and Advance Web Technologies
Department of Computer Science
Glassfish vs. Tomcat
Historically, if you wanted to get good HTTP performance from Tomcat you really needed to have an Apache web server to sit in front of Tomcat which involved more setting up and extra administrative work.
Since GlassFish v1 (May 2006), Grizzly is the HTTP frontend of the application server.
It's a 100% Java NIO framework that provides the same performance as Apache, only it's written in Java and integrated straight into the application server.
Sun is the original creator of Tomcat
Not a full-application server
32
Multimedia and Advance Web Technologies
Department of Computer Science
Other Java web application-capable Servers
33
Multimedia and Advance Web Technologies
Department of Computer Science
Commercial Deployment
34
Multimedia and Advance Web Technologies
Department of Computer Science
Creating a new Web Application
JSP File
35
Multimedia and Advance Web Technologies
Department of Computer Science
Creating a new Web Application
Sample Run
36
Multimedia and Advance Web Technologies
Department of Computer Science
Project: HelloWeb
37
Multimedia and Advance Web Technologies
Department of Computer Science
HelloWeb: Directories and Files
38
Multimedia and Advance Web Technologies
Department of Computer Science
39
Adding a Java source package and a source file
NameHandler.java
Multimedia and Advance Web Technologies
Department of Computer Science
Java Package
Right-click Source Packages
40
Multimedia and Advance Web Technologies
Department of Computer Science
Java Package
Add a Java Class, specify Package name
Java Package
41
Multimedia and Advance Web Technologies
Department of Computer Science
Java Package
Add a Java Class
42
Multimedia and Advance Web Technologies
Department of Computer Science
Java Package
Edit the Java Class
String name;
public NameHandler()
name = null;
43
Multimedia and Advance Web Technologies
Department of Computer Science
Generating Getter and Setter Methods
Right-click name field in the Source editor
Selection: Name Field / Refactor / Encapsulate Fields
44
Multimedia and Advance Web Technologies
Department of Computer Science
Generating Getter and Setter Methods
Notice that Fields' Visibility is by default set to private, and Accessors' Visibility to public, indicating that the access modifier for class variable declaration will be specified as private, whereas getter and setter methods will be generated with public and private modifiers, respectively.
45
Multimedia and Advance Web Technologies
Department of Computer Science
Generating Getter and Setter Methods
Select the Refactor button.
46
Multimedia and Advance Web Technologies
Department of Computer Science
Notice that the variable declaration has changed.
Get and set functions with implementation have been added as well.
Results of Refactoring
47
Multimedia and Advance Web Technologies
Department of Computer Science
48
Editing the Default JSP file
Adding and Customising
a Form, input text field, submit button
Multimedia and Advance Web Technologies
Department of Computer Science
49
Invoke the palette: from the menu, select (Window/Palette): or press Ctrl+Shift+8
expand HTML Forms
Inserting a Form
Multimedia and Advance Web Technologies
Department of Computer Science
50
expand HTML Forms and drag a Form item to a point after the <h1> tags in the Source Editor.
The Insert Form dialog box displays.
Inserting a Form
Multimedia and Advance Web Technologies
Department of Computer Science
51
Specify the following values:
Click OK.
Specifying an action
Multimedia and Advance Web Technologies
Department of Computer Science
52
An HTML form is automatically added to the index.jsp file.
Source Generated
Multimedia and Advance Web Technologies
Department of Computer Science
53
Drag a Text Input item to a point just before the </form> tag, then specify the following values:
Adding an Input Text Field
Multimedia and Advance Web Technologies
Department of Computer Science
54
Input Text Field
Source Generated
Multimedia and Advance Web Technologies
Department of Computer Science
55
Drag a Button item to a point just before the </form> tag. Specify the following values:
Click OK. An HTML button is added between the <form> tags.
Adding a Submit Button
Multimedia and Advance Web Technologies
Department of Computer Science
56
Type Enter your name: just before the first <input> tag, then change the default Hello World! text between the <h1> tags to Entry Form.
Adding some extra labels, tidying up your code
Right-click within the Source Editor and choose Format
(Alt-Shift-F) to tidy the format of your code.
Multimedia and Advance Web Technologies
Department of Computer Science
57
index.jsp: Source Generated
We would like to pass this to our server
Multimedia and Advance Web Technologies
Department of Computer Science
58
Creating a JSP file that generates the server’s response
response.jsp
Multimedia and Advance Web Technologies
Department of Computer Science
59
In the Projects window, right-click the HelloWeb project node and choose New > JSP. The New JSP File wizard opens.
Name the file response, and click Finish.
Notice that a response.jsp file node displays in the Projects window beneath index.jsp, and the new file opens in the Source Editor.
Adding a JSP File
Multimedia and Advance Web Technologies
Department of Computer Science
60
JSP Source File Generated: response.jsp
Multimedia and Advance Web Technologies
Department of Computer Science
61
In the Palette to the right of the Source Editor, expand JSP and drag a Use Bean item to a point just below the <body> tag in the Source Editor.
The Insert Use Bean dialog opens.
Specify the values shown in the following figure.
Adding a Use Bean item
The class NameHandler belongs to the package we have set earlier
Multimedia and Advance Web Technologies
Department of Computer Science
62
JSP Source File Generated: response.jsp
Notice that the <jsp:useBean> tag is added beneath the <body> tag.
Multimedia and Advance Web Technologies
Department of Computer Science
63
Drag a Set Bean Property item from the Palette to a point just before the <h1> tag and click OK.
In the <jsp:setProperty> tag that appears, delete the empty value attribute and edit as follows. Delete the value = "" attribute if the IDE created it! Otherwise, it overwrites the value for name that you pass in index.jsp.
Adding a Set Bean property item
Multimedia and Advance Web Technologies
Department of Computer Science
64
Drag a Set Bean Property item from the Palette to a point just before the <h1> tag and click OK.
In the <jsp:setProperty> tag that appears, delete the empty value attribute and edit as follows. Delete the value = "" attribute if the IDE created it! Otherwise, it overwrites the value for name that you pass in index.jsp.
Adding a Set Bean property item
Multimedia and Advance Web Technologies
Department of Computer Science
65
Drag a Get Bean Property item from the Palette and drop it after the comma between the <h1> tags.
Specify the following values in the Insert Get Bean Property dialog:
Adding a Get Bean property item
Insert a Get Bean Property item here!
Multimedia and Advance Web Technologies
Department of Computer Science
66
the user input coming from index.jsp becomes a name/value pair that is passed to the request object.
When you set a property using the <jsp:setProperty> tag, you can specify the value according to the name of a property contained in the request object.
JSP Source Code Generated
Therefore, by setting property to name, you can retrieve the value specified by user input.
Multimedia and Advance Web Technologies
Department of Computer Science
67
Sample Run
User input
Response from the JSP file
Multimedia and Advance Web Technologies
Department of Computer Science
68
Sample Run
User input
Response from the JSP file
Index.jsp
NameHandler.java
Main interface, Html with form
Invokes response.jsp through form action.
response.jsp
Class NameHandler containing user data, get and set methods
Generates the server’s response
Defines a JavaBean to connect the class NameHandler to
the user’s input via a form text field (name).
Multimedia and Advance Web Technologies
Department of Computer Science
69
Project
Index.jsp
NameHandler.java
Main interface, Html with form
Invokes response.jsp through form action.
response.jsp
Class NameHandler containing user data, get and set methods
Generates the server’s response
Defines a JavaBean to connect the class NameHandler to
the user’s input via a form text field (name).
Multimedia and Advance Web Technologies
Department of Computer Science
70
The Java EE specification defines how the web application can be archived into a web application archive (WAR)
• WAR files are
– Java archives with a .war extension
– Packaged using the same specification as zip files
– Understood by all Java EE compliant application servers
• WAR files can be directly deployed in servlet containers such as Tomcat
Packaging Web Applications
Multimedia and Advance Web Technologies
Department of Computer Science
71
• The WAR file will be placed in the “dist” sub-directory of your project folder
NetBeans WAR files
Multimedia and Advance Web Technologies
Department of Computer Science
The End
72
Multimedia and Advance Web Technologies
Department of Computer Science
Exercise
Q1. Explain J2SE, JEE and J2EE.
Q2. Explain Java web applications with its components.
Q3. What is Java Servlets.
Q4. How do servlets work?
Q5. Explain JEE containers with diagram.
Q6. Explain Java Servlets.
Q7. Explain Java Beans
Q8. What is EJB?
Q9. Explain Glassfish.
73
Multimedia and Advance Web Technologies
Department of Computer Science
Q10. What is the difference between Glassfish and Tomcat.
Q11. Explain Oracle GlassFish server and Oracle WebLogic server.
Q12. Explain the Web Application Archive (WAR).
74
Multimedia and Advance Web Technologies
Department of Computer Science
Q13. A Java platform comprises with supporting class libraries and .
Q14. A Java web application generates interactive web pages containing various types of markup language and.
75
Multimedia and Advance Web Technologies
Department of Computer Science
Q15. Java EE builds upon the Java SE platform and provides a set of
Q16. XML deployment descriptors are.
76
Multimedia and Advance Web Technologies
Department of Computer Science
Q17. Servlets run inside a
Q18. Servlets do not have a.
77
Multimedia and Advance Web Technologies
Department of Computer Science
Q19. GlassFish uses a derivative of Apache Tomcat as the
Q20. To make a WAR for your NetBeans project, right click on the project node and select
78
Multimedia and Advance Web Technologies
Department of Computer Science