|< 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
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.
attributeAdded () method
attributeRemoved () method
attributeReplaced () method
CLASSPATH environment variable
context initialisation parameters
context initialization parameters
contextDestroyed () method
contextInitialized () method
default pages see welcome pages.
deployment descriptor, 8
deployment descriptor validation
Exploded Directory Format
file based security
getInitParameter() method, ServletContext object
getInitParameterNames() method, ServletContext
HTTP based authentication
HTTP Error 500, 14
init() method, MainServlet
reference to web sites
servlet context initialization parameters see
servlet mappings, 12
ServletContext initialization parameter
ServletContext object, 5
servlets 2.3 specification
tags see elements.
WAR see Web Application Archive.
Web Application Archive
Web Application Archive format
web application archives
web application life cycle
web store application
WEB-INF directory, 2
Xalan XML parser
XML parser, JAXP compatible
|< Free Open Study >|| |