5-Web Application Deployment: Juan M. Gimeno, Josep M. Rib o January, 2008
5-Web Application Deployment: Juan M. Gimeno, Josep M. Rib o January, 2008
January, 2008
INDEX
Contents
1. Introduction.
2. HTTP protocol
3. Servlets
1
INDEX
• Concept
• Deployment descriptor
• WAR files
• Package-structures servlets
2
Intro. to web applications in Java. 5- Web application deployment. Concept INDEX
3
Intro. to web applications in Java. 5- Web application deployment. File structure INDEX
• WEB-INF (directory)
This directory contains the deployment descriptor and the
java packages needed by the web application
This directory is explained in the following slide
• META-INF (directory)
It contains some meta information about the jar or war
files
jar/war files are explained below
4
Intro. to web applications in Java. 5- Web application deployment. File structure INDEX
• classes (directory)
Directory which contains classes which are used in the
web application (e.g., beans and servlets). This classes
are organized into directories according to their package
structure.
(e.g., the class elems.Book will be stored as
classes/elems/Book.class
5
Intro. to web applications in Java. 5- Web application deployment. File structure INDEX
• lib (directory)
Directory which contains classes which are used in the
web application (e.g., beans and servlets). This classes
are packaged and compressed in a .jar file. Example:
classes.jar
WebDir
web
BuyProcess.jsp
WEB-INF
classes
elems
Book.class
Cart.class
lib
6
Intro. to web applications in Java. 5- Web application deployment. File structure INDEX
Deployment descriptor:
It is a file called WEB-INF/web.xml which contains infor-
mation useful in order to deploy the web application
7
Intro. to web applications in Java. 5- Web application deployment. File structure INDEX
<web-app>
<context-param> ...</context-param>
<servlet>...</servlet>
<servlet-mapping>...</servlet-mapping>
<welcome-file-list> ... </welcom-file-list>
<taglib>...</taglib>
<ejb-ref>...</ejb-ref>
</web-app>
• http://java.sun.com/webservices/docs/1.0/tutorial/doc/
JavaWSTutorialTOC.html
8
Intro. to web applications in Java. 5- Web application deployment. File structure INDEX
WebDir
WEB-INF WEB-INF
classes classes
elems elems
Book.class Book.class
Cart.class Cart.class
lib lib
9
Intro. to web applications in Java. 5- Web application deployment. Location INDEX
1. At CATALINA HOME/webapps
2. In a context defined at
CATALINA HOME/conf/server.xml
3. In a context.xml file
10
Intro. to web applications in Java. 5- Web application deployment. Location INDEX
1. At CATALINA HOME/webapps
(i.e., CATALINA HOME/webapps/WebDir)
11
Intro. to web applications in Java. 5- Web application deployment. Location INDEX
Example:
The location of the application mywebap may be described
by means of the following file:
CATALINA HOME/conf/Catalina/localhost/mywebap.xml
12
Intro. to web applications in Java. 5- Web application deployment. war file INDEX
<Context path="/servletTest"
docBase="/home/josepma/test/test.war"
reloadable="true" debug="0" />
13
Intro. to web applications in Java. 5- Web application deployment. Deployment example INDEX
Example location:
introapweb/examples/ex5.1
14
Intro. to web applications in Java. 5- Web application deployment. Deployment example INDEX
Deployment procedure:
• Directory /home/josepma/web/WEB-INF
• Directory /home/josepma/web/WEB-INF/classes
• Directory /home/josepma/web/WEB-INF/lib
15
Intro. to web applications in Java. 5- Web application deployment. Deployment example INDEX
<web-app>
<servlet>
<servlet-name>Servlet1</servlet-name>
<servlet-class>Parameter</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>Servlet1</servlet-name>
<url-pattern>/serv</url-pattern>
</servlet-mapping>
</web-app>
This file defines the servlet class and maps it to the label
/serv
16
Intro. to web applications in Java. 5- Web application deployment. Deployment example INDEX
<form action="http://localhost:8080/ex5.1/serv"
method="get">
<form action="serv"
method="get">
17
Intro. to web applications in Java. 5- Web application deployment. Deployment example INDEX
<user username="someuser"
password="somepassw"
roles="manager"/>
18
Intro. to web applications in Java. 5- Web application deployment. Deployment example INDEX
19
5. The web layer. 5.5 Web applications deployment. Automation INDEX
20
5. The web layer. 5.5 Web applications deployment. Automation INDEX
21
5. The web layer. 5.5 Web applications deployment. Automation INDEX
22
5. The web layer. 5.5 Web applications deployment. Automation INDEX
Example location:
introapweb/examples/ex5.2
• General description
This is the example 5.1 with the building and deployment
processes automated using the ant build tool
Access http://localhost:8080/ex5.2/formParam.html
23
5. The web layer. 5.5 Web applications deployment. Package-structures servlets INDEX
com.mycompany.mypackage.MyServlet.class
/WEB-INF/classes/com/mycompany/mypackage/MyServlet.class
package com.mycompany.mypackage;
24
5. The web layer. 5.5 Web applications deployment. Package-structures servlets INDEX
<web-app>
<servlet>
<servlet-name>Servlet2</servlet-name>
<servlet-class>com.mycompany.mypackage.MyServlet
</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>Servlet2</servlet-name>
<url-pattern>/serv2</url-pattern>
</servlet-mapping>
</web-app>
25
5. The web layer. 5.5 Web applications deployment. Package-structures servlets INDEX
References
26