| < Free Open Study > |
|
In this section we will discuss some of the new features of the Servlet specification that relate to web applications.
To be truly useful, a web application usually needs to have access to other libraries, both from within the J2EE framework, and from external sources. These libraries are normally contained within JAR files. For example, a web application that needs to access XML features would need to have a file such as xerces.jar available to the application.
In prior versions of the Servlet specification, you had to include all of the JAR files required by a web application in the web application archive, in the WEB-INF/lib directory of the archive. This is obviously not ideal, as it add extra weight to each web application, as well as meaning that we probably have several versions of the same JAR on each server.
In the latest version of the Servlet specification, 2.3, we are able to express dependencies on these external JAR files using the MANIFEST.MF file in the web archive's META-INF directory. Expressing dependencies in this way allows a web container to reject deployment of a web application if a dependency cannot be satisfied. This should prevent the occurrence of cryptic runtime errors when JAR files cannot be found.
Note that it is also possible to declare a dependency on a particular version of a library. It is then up to the server to find the correct package at deployment time.
The 2.3 version of the Servlet specification introduces what appears at first sight to be a small change to the classloading mechanism for web applications. This apparently small change actually has a very big impact. In previous versions of the Servlet specification, a web application could see and use the server's implementation classes. In the latest version, this is impossible.
This may not sound like much, but it prevents situations where a collision between web application classes and server implementation classes may occur. This had become a significant problem with XML parsers, as each server had a parser to read and validate deployment descriptors, and lots of applications also used XML parsers. If the parsers implemented different standards, this could lead to an unsolvable conflict.
In this chapter we have examined many features relating to the deployment of web applications based on the Servlets 2.3 specification.
We noted that web applications can be deployed in different ways depending on whether we are deploying our application in a production or development situation. For production we can use the WAR file format, and for development we can deploy in the Exploded Directory format.
We then looked at some of the aspects of the web application that can be configured in the deployment descriptor XML file for a web application. These included:
Servlet definitions and mappings
Welcome pages
Error pages
Declarative security
ServletContext initialization
We also discussed a strategy for validating the well-formedness and conformity of our deployment descriptors, and developed a simple validator application to inform us of errors.
To illustrate the points we had made earlier in the chapter, we then created a sample web store application, and deployed it as a WAR in Tomcat.
At the end of the chapter, we considered aspects of servlet deployment that had changed in the latest version (2.3) of the Servlet specification, including how classes are loaded and JAR dependencies within WAR files.
In the next chapter we will discuss how to track client information across requests, using sessions.
! |
---|
!DOCTYPE> element
|
A |
---|
addToCart() method
archives
attributeAdded () method
attributeRemoved () method
attributeReplaced () method
auth-constraint> element
authentication
auth-method> element
authorization
|
B |
---|
basic authentication
Basic Authentication
|
C |
---|
CartServlet servlet
CheckOutServlet servlet
classes
classloading
CLASSPATH environment variable
confidentiality
context initialisation parameters
context initialization parameters
context> element
contextDestroyed () method
contextInitialized () method
context-param> element
contexts
|
D |
---|
default pages see welcome pages. deployment
deployment descriptor, 8
deployment descriptor validation
description> element
displayCart() method
display-name> element
DocumentBuilder object
doGet() method
doGetOrPost() method
doPost() method
|
E |
---|
elements
error pages
error-page> element
exception-type> element
Exploded Directory Format
|
F |
---|
file based security
form-login-config> element
|
G |
---|
GenericServlet class
getInitParameter() method, ServletContext object
getInitParameterNames() method, ServletContext
|
H |
---|
HTTP based authentication |
HTTP Error 500, 14 http-method> element
|
I |
---|
init() method, MainServlet |
init-param> element
integrity
interfaces
ItemAlreadyAddedException
|
J |
---|
j_security_check resource
JAR dependencies
java.lang.ArithmeticException
javac
JSP pages
|
L |
---|
location> element
login-config> element
|
M |
---|
MainServlet servlet
mapping
methods
|
P |
---|
parameters
param-name> element
param-value> element
private resources
products> element
|
R |
---|
realm-name> element
reference to web sites
reloadable parameter
role-name> element
|
S |
---|
security
security-constraint> element
servlet code
servlet context initialization parameters see
servlet definition
servlet mappings, 12 servlet> element
servlet-class> element
ServletContext initialization parameter
ServletContext object, 5
ServletContextAttributeListener interface
ServletContextListener interface
servlet-mapping> element
servlet-name> element
servlets
servlets 2.3 specification
store.war file
|
T |
---|
tags see elements. Tomcat
tomcat-users> element
|
U |
---|
url-pattern> element
|
W |
---|
WAR see Web Application Archive. Web Application Archive
Web Application Archive format
web application archives
web application life cycle
web applications
web store application
web-app_2_3.dtd
web-app> element
WEB-INF directory, 2
web-resource-collection> element
web-resource-name> element
welcome pages
welcome-file-list> element
welcome-page> element
|
X |
---|
Xalan XML parser
XML
XML parser, JAXP compatible
|
| < Free Open Study > |
|