Slide 3 - Java Web Application
Slide 3 - Java Web Application
Objectives
Introduction to java web application
+ The core and basic of Java web server technologies
+ Java web application technologies
Setup Environment :
Deployment Descriptor
05/20/23 2/41
Java web application
• Java web application provides dynamic web pages
for communication between client & server
• Java provides support for web application
through Servlets and JSPs – core java web
technology
• Java web server: web container- servlet container-
servlet engine
05/20/23 3/41
Java web application
• Application server provide J2EE technology for java web application
05/20/23 4/41
File and Directory Structure
• A Place for Everything and Everything in Its Place.
• Construct the file and directory structure of a Web
Application that may contain:
static content,
JSP pages,
servlet classes,
the deployment descriptor,
tag libraries,
JAR files and Java class files;
and describe how to protect
resource files from HTTP access.
05/20/23 5/41
Special Directories Beneath the Context
Root
• /WEB-INF/classes—for classes that exist as separate
Java classes (not packaged within JAR files).
• /WEB-INF/ lib—for JAR files, supporting classes that
connect to databases—whatever library.
• web.xml, the deployment descriptor file.
05/20/23 6/41
Deployment Descriptor
• Deployment descriptor describes the classes,
resources and configuration of the application
• When the web server receives a request for the
application, it uses the deployment descriptor to
map the URL of the request to the code that handle
the request.
• The deployment descriptor is a file named web.xml.
It resides under the WEB-INF/ directory.
• The file is an XML file whose root element is <web-
app>
05/20/23 7/41
Structure of the Deployment Descriptor.
05/20/23 8/41
Deployment Descriptor simple web.xml
<?xml version="1.0" encoding="ISO-8859-1"?>
<web-app xmlns="http://java.sun.com/xml/ns/j2ee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation=http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd
version="2.4">
<servlet-mapping>
<servlet-name>FirstServlet</servlet-name>
<url-pattern>/FirstServlet</url-pattern>
</servlet-mapping>
</web-app>
05/20/23 9/41
Welcome Files
<welcome-file-list>
<welcome-file>index.html</welcome-file>
<welcome-file>index.jsp</welcome-file>
<welcome-file>mainlibrary/catalog.jsp</welcome-file>
</welcome-file-list>
05/20/23 10/41
Packaging Your Web Application
Web modules are packaged as JAR files with
a .war (web archive) extension
WARs are packaged for a different purpose: to
make it as easy as possible for a web
container to deploy an application.
Web modules contain servlet class files, web
files, supporting class files, image and HTML
files, and web application deployment
descriptor.
NetBean: Project name-> Build
05/20/23 11/41
Deploy web application
• Several web containers have automatic deployment
mechanisms.
• The server recommended for this course—Tomcat
7.x or Glassfish 4.x—has a “webapps” directory.
• Place a WAR file in this directory, and Tomcat (by
default) will un-jar the contents into the file system
under the webapps directory.
• a context root directory is the same name as the
WAR file (but without the .war extension)— then
makes the application available for use.
05/20/23 12/41
Create first web application
05/20/23 13/41
Create first web application
05/20/23 14/41
Create first web application
05/20/23 15/41
Create first web application
05/20/23 16/41
Summary
Java Web application
• Core technology of Java web
• Deployment Descriptor
05/20/23 17/41
Constructive question
Compare general web server and Java web
server
When a user enter username and password to
login a java web application, what does the
server do? List the tasks in order of execution.
When a user accesses a java web application
from a browser, what does the web server do?
As a developer, how do you deploy web app?
05/20/23 18/41