Advanced Deployment Issues

 < Free Open Study > 



In this section we will discuss some of the new features of the Servlet specification that relate to web applications.

JAR Dependencies

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.

Classloading

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.

Summary

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

  • deployment descriptor, 9

A

addToCart() method

  • CartServlet, web store application, 28

archives

  • web application archives, 4

attributeAdded () method

  • web application life cycle, 7

attributeRemoved () method

  • web application life cycle, 7

attributeReplaced () method

  • web application life cycle, 7

auth-constraint> element

  • deployment descriptor, web store application, 33

  • HTTP based authentication, 18

authentication

  • description, 17

auth-method> element

  • basic authentication, 19

authorization

  • description, 17

B

basic authentication

  • !see also p.HTTP based authentication.

  • HTTP Authentication, 17

Basic Authentication

  • steps in setting up file-based, 18

C

CartServlet servlet

  • implementing, code, 28

  • web store application, 24

CheckOutServlet servlet

  • implementing, code, 30

  • web store application, 25

classes

  • GenericServlet class, 12

classloading

  • servlets 2.3 specification, 37

CLASSPATH environment variable

  • executing deployment descriptor validator, 22

  • web application development problem, 4

confidentiality

  • description, 17

context initialisation parameters

  • deployment descriptor, 13

  • ServletContext object, 13

context initialization parameters

  • defining initialization parameter, 14

context> element

  • deploying web store application to Tomcat, 35

contextDestroyed () method

  • web application life cycle, 6

contextInitialized () method

  • web application life cycle, 6

context-param> element

  • deployment descriptor, 10

contexts

  • defining within Tomcat 4, 6

D

default pages see welcome pages.

deployment

  • Exploded Directory Format, 4

  • Web Application Archive, 4

deployment descriptor, 8

  • element order, 19

  • error pages, 14

  • example, 9

  • file based security, 17

  • servlet context initialisation parameters, 13

  • servlet definitions, 11

  • servlet mappings, 12

  • servlets 2.3 specification rules, 9

  • tag order, 19

  • web store application

    • code, 31

    • security policy, 32

  • welcome pages, 16

deployment descriptor validation

  • DTD compliance options, 20

  • executing the validator, 22

  • validating, 20

  • web-app_2_3.dtd, web site, 20

  • XML parser, web site, 20

description> element

  • deployment descriptor, 10

displayCart() method

  • CartServlet, web store application, 29

display-name> element

  • deployment descriptor, 9

DocumentBuilder object

  • web store application, 25

doGet() method

  • CartServlet, web store application, 28

  • MainServlet, web store application, 26

doGetOrPost() method

  • CartServlet, web store application, 28

  • CheckOutServlet, web store application, 30

  • MainServlet, web store application, 26

doPost() method

  • CartServlet, web store application, 28

  • MainServlet, web store application, 26

E

elements

  • !DOCTYPE> element, 9

  • auth-constraint> element, 18, 33

  • auth-method> element, 19

  • context-param> element, 10

  • deployment descriptor element order, 19

  • description> element, 10

  • display-name> element, 9

  • error-page> element, 10, 15, 23

  • exception-type> element, 15

  • form-login-config> element, 33

  • http-method> element, 18

  • init-param> element, 12

  • location> element, 15

  • login-config> element, 18, 33

  • param-name> element, 12

  • param-value> element, 12

  • realm-name> element, 19

  • role-name> element, 18

  • security-constraint> element, 18

  • servlet> element, 10, 11, 13, 19, 23, 31

  • servlet-class> element, 12

  • servlet-mapping> element, 10, 13, 19, 31

  • servlet-name> element, 12, 13

  • tomcat-users> element, 19

  • url-pattern> element, 13, 18

  • web-app> element, 9

  • web-resource-collection> element, 18, 33

  • web-resource-name> element, 18

  • welcome-file-list> element, 10

  • welcome-page> element, 17

error pages

  • controlling error displayed, 15

  • deployment descriptor, 14

  • programmer accessing trace file, 16

error-page> element

  • deployment descriptor, 10

  • executing deployment descriptor validator, 23

  • java.lang.ArithmeticException, 15

exception-type> element

  • error pages, 15

Exploded Directory Format

  • deployment of web application, 4

F

file based security

  • authentication, 17

  • authorization, 17

  • confidentiality, 17

  • deployment descriptor, 17

  • integrity, 17

form-login-config> element

  • deployment descriptor, web store application, 33

G

GenericServlet class

  • servlet definition, 12

getInitParameter() method, ServletContext object

  • context initialisation parameters, 14

  • servlet definition, 12

getInitParameterNames() method, ServletContext

  • object

  • context initialisation parameters, 14

H

HTTP based authentication

  • !see also basic authentication.

  • basic authentication, 17

  • file based security, 17

  • securing collection of resources, 18

  • web site, 17

HTTP Error 500, 14

http-method> element

  • basic authentication, 18

I

init() method, MainServlet

  • deployment descriptor, web store application, 31

  • web store application, 25

init-param> element

  • servlet definition, 12

integrity

  • description, 17

interfaces

  • ServletContextListener interface, 6

ItemAlreadyAddedException

  • CartServlet, web store application, 29

  • deployment descriptor, web store application, 32

J

j_security_check resource

  • deployment descriptor, web store application, 34

JAR dependencies

  • servlets 2.3 specification, 37

java.lang.ArithmeticException

  • error pages, 15

javac

  • compiling classes, web store application, 34

JSP pages

  • sent to client in web applications, 3

L

location> element

  • error pages, 15

login-config> element

  • basic authentication, 18

  • deployment descriptor, web store application, 33

M

MainServlet servlet

  • deployment descriptor, web store application, 31

  • displaying store contents, code, 25

  • web store application, 24

mapping

  • servlet mapping, 12

methods

  • attributeAdded () method, 7

  • attributeRemoved () method, 7

  • attributeReplaced () method, 7

  • contextDestroyed () method, 6

  • contextInitialized () method, 6

  • getInitParameter() method, 12, 14

  • getInitParameterNames() method, 13

  • init() method, 25, 31

P

parameters

  • reloadable parameter, 35

  • servlet context initialisation parameters, 13

  • ServletContext initialization parameter, 25

param-name> element

  • servlet definition, 12

param-value> element

  • servlet definition, 12

private resources

  • WEB-INF directory, 3

products> element

  • web store application, 27

R

realm-name> element

  • basic authentication, 19

reference to web sites

  • deployment descriptor validation, 20

  • HTTP based authentication, 17

  • validating XML parser, 20

  • web applications deployment control, 35

  • XML conform to Sun web application DTD, 9

reloadable parameter

  • deploying web store application to Tomcat, 35

role-name> element

  • basic authentication, 18

S

security

  • declarative security, 32

  • defining users in Tomcat, 19

  • deployment descriptor, web store application, 32

  • file based security, 17

    • HTTP authentication, 17

  • programmatic security, 32

security-constraint> element

  • basic authentication, 18

servlet code

  • web store application, 24

servlet context initialization parameters see

  • context initialization parameters.

servlet definition

  • GenericServlet class, 12

servlet mappings, 12

servlet> element

  • deployment descriptor, 10

  • deployment descriptor element order, 19

  • deployment descriptor, web store application, 31

  • executing deployment descriptor validator, 23

  • servlet mapping, 13

  • servlets definition, 11

servlet-class> element

  • servlet definition, 12

ServletContext initialization parameter

  • web store application, 25

ServletContext object, 5

  • context initialisation parameters, 13

  • getInitParameter() method, 14

  • getInitParameterNames() method, 14

  • servlet definition, 12

  • web application life cycle, 6

  • web store application, 26

ServletContextAttributeListener interface

  • methods, 7

  • web application life cycle, 7

ServletContextListener interface

  • methods, 6

  • web application life cycle, 6

servlet-mapping> element

  • deployment descriptor, 10

  • deployment descriptor element order, 19

  • deployment descriptor, web store application, 31

  • servlet mappings, 13

servlet-name> element

  • servlet definition, 12

  • servlet mapping, 13

servlets

  • defined in web applications, 11

  • new features web applications, 36

servlets 2.3 specification

  • classloading, 37

  • deployment descriptor rules, 9

  • JAR dependencies, 37

store.war file

  • packaging the web store application, 34

T

tags see elements.

Tomcat

  • contexts, defining within Tomcat 4, 6

  • defining users, 19

  • deploying web store application to Tomcat, 34

tomcat-users> element

  • defining users in Tomcat, 19

U

url-pattern> element

  • basic authentication, 18

  • servlet mapping, 13

W

WAR see Web Application Archive.

Web Application Archive

  • example of file creation, 4

  • packaging the web store application, 34

Web Application Archive format

  • deployment of web application, 4

web application archives

  • options for deployment, 4

web application life cycle

  • creation and destruction, 6

web applications

  • deployment control, web site, 35

  • deployment descriptor, 8

  • deployment example, 24

  • deployment nightmares, previous, 2

  • directory structure, 2

  • explained, 2

  • JSP pages sent to client, 3

  • life cycle, 6

  • resources not to access or download, 3

  • servlet specification, new features, 36

  • ServletContext object, 5

  • servlets defined in, 11

  • structure, 2

  • XML conform to Sun DTD, web site, 9

web store application

  • adding users, 34

  • deploying to Tomcat, 34

  • deployment descriptor, code, 31

  • javac, compiling classes, 34

  • packaging the application, 34

  • servlet code, 24

  • web applications deployment example, 24

web-app_2_3.dtd

  • deployment descriptor validation, web site, 20

web-app> element

  • deployment descriptor, 9

WEB-INF directory, 2

  • private resources not to access or download, 3

web-resource-collection> element

  • basic authentication, 18

  • deployment descriptor, web store application, 33

web-resource-name> element

  • basic authentication, 18

welcome pages

  • defining a welcome page, 17

  • deployment descriptor, 16

welcome-file-list> element

  • deployment descriptor, 10

welcome-page> element

  • welcome pages, 17

X

Xalan XML parser

  • executing deployment descriptor validator, 22

XML

  • validating XML parser, web site, 20

XML parser, JAXP compatible

  • executing deployment descriptor validator, 22



 < Free Open Study > 



Professional Java Servlets 2.3
Professional Java Servlets 2.3
ISBN: 186100561X
EAN: 2147483647
Year: 2006
Pages: 130

Similar book on Amazon

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net