Archive for March, 2009

Chapter 7: Web Application Confi guration The order

Tuesday, March 31st, 2009

Chapter 7: Web Application Confi guration The order of elements inside the element must be as shown previously, but some elements are optional, and others may appear multiple times. The following table may be used as a quick reference to the functionality of each element. A more detailed explanation is provided later in the chapter. Element Description How Many?
Image for an application Display name for a Web application Description used for display A Boolean value indicating whether an application is distributable across servers Initialization parameters for the entire application Defines a filter Valve Defines a URL pattern to which the given filter needs to be applied Defines a lifecycle event listener Defines a servlet Defines a URL pattern to invoke a named servlet Defines session configuration Defines the MIME type for a given file type A list of files to be served if no resource is specified explicitly in the URL Defines a Java exception or an HTTP code-based error page Declares a tag library Declares a resource-administered object Declares an external resource 0 or 1 0 or 1 0 or 1 0 or 1 0 or more 0 or more 0 or more 0 or more 0 or more 0 or more 0 or 1 0 or more 0 or 1 0 or more 0 or more 0 or more 0 or more

If you looking for unlimited one inclusive web hosting plan please check cheap web hosting website.

Chapter 7: Web Application Confi guration Following is

Tuesday, March 31st, 2009

Chapter 7: Web Application Confi guration Following is a Servlet 2.3 DTD-based web.xml: Following is a Servlet 2.4 schema-based web.xml: Finally, the new Servlet 2.5 schema-based web.xmlis as follows: If you use a Servlet 2.3 type deployment descriptor, Tomcat ignores all the new Servlet and JSP features that you use in your application, such as JSP EL (Expression Language). The Servlet 2.3 Style Deployment Descriptor The web.xmlfile takes the following generalized form:
(continued)

If you looking for unlimited one inclusive web hosting plan please check web hosting plan website.

Chapter 7: Web Application Confi guration As you

Monday, March 30th, 2009

Chapter 7: Web Application Confi guration As you can see, the name of the extension is referenced in each entry. This is suffixed by a specific attribute name describing the extension. The name of the extension in this file is an alias for the extension s name as defined in the jarfile. Thus, the declaration of the extension s alias is accomplished by simply prefixing it to the attribute names; it does not need to be explicitly defined. The extension s proper name is referred to in the first entry. The server will investigate the contents of each jar file installed on it and check packages to determine whether the names match. The specifications and implementation version numbers are self-explanatory, as should be the vendor name that is specified in the Implementation-Vendor attribute. The vendor should be a globally unique ID. The custom of including the reversed host name is common. In the preceding example, this is com.wrox. Finally, the Implementation-URL should be provided, giving the location of additional information and often download instructions. For our purpose, this is the most useful line. If the extension is not installed, the URL should provide enough information to ensure that it is made available to the Web application by other means. The manifest file is typically generated automatically when a Web application is packaged as a Web archive ( .war) file. Packaging Web applications for distribution as .war files is described in Chapter 2 . The Context File The context file (context.xml) contains the configuration for the Web applications Context . As you saw in Chapter 4 , the Context represents a Web application, and has all the configurable elements for it. This is not the only place where the Web applications Contextis defined: Chapter 5 describes this in greater detail, and lists all the places where the Web application Context can be configured. Understanding the Deployment Descriptor (web.xml) A deployment descriptor is an XML file that contains configuration information used by the Web application for execution on the Servlet engine. The deployment descriptor for a Web application is the /webapps//WEB-INF/web.xml file. There is another web.xml file that is applicable for all Web applications deployed in the servlet Engine, and this is located under /conf. This section examines application-specific deployment only. However, the configuration-related information is valid for all deployment descriptors. The Servlet 2.5 specification uses a schema for the deployment descriptor older specifications (Servlet 2.3 and earlier) still use a Document Type Definition (DTD). Both are still supported for backward compatibility with existing Web applications. Because you might need to support existing Web applications, this chapter covers both the older Servlet 2.3 style web.xmland the schema-based versions. The first few lines of the deployment descriptor indicate whether it is the Servlet 2.4/2.5 schema-based web.xmlor the older DTD-based version.

If you looking for unlimited one inclusive web hosting plan please check unlimited web hosting website.

Chapter 7: Web Application Confi guration This would

Sunday, March 29th, 2009

Chapter 7: Web Application Confi guration This would output the current date whenever it is placed in a JSP file. To enable the container to recognize which Java class to invoke when it comes across the tag, you must provide a configuration file that lists the number of arguments the tag can have, its name (in this case, the tag s name is today and the library it belongs to is date). The tag library configuration files have a .tld extension. The configuration of a tag library is the territory of developers and designers, and thus beyond the scope of this blog. The lib Directory This directory contains packaged Java libraries ( .jar files) that the application requires and that are bundled with the application. JAR files that are placed here are available only to the Web application. If the libraries are to be accessed across Web applications, they should be placed under / lib. This is different from earlier Tomcat versions, which had a /shared/libdirectory for libraries that needed to be shared with other Web applications. The following section describes what aspects of the web.xml configuration file you can administer. The META-INF Directory As mentioned, the WEB-INF directory represents the private resources of an application. However, this is not the only directory for private resources. A Web application may have an optional META-INFdirectory that contains deployment information for tools that create war files and resources that applications may rely on. Therefore, a Servlet container will refuse to show the contents of the META-INF directory to a client. The META-INF directory can contain two configuration files: the manifest file ( MANIFEST.MF) and the context file (context.xml). The Manifest File The MANIFEST.MF file is an optional configuration file for a Web application. It contains a list of JAR files on which an application relies. The container can then use this to check for all the required libraries that are to be made available for the Web application. An entry in this text file should be provided as follows, on a single line: Extension-List: extension1 extension2 extension3 Each extension name is separated by a space and is placed as a separate entry in the MANIFEST.MFfile. The entries are named with a prefix, followed by the string -Extension-Name, which is an attribute name, as shown here: extension1-Extension-Name: com.wrox.extension1 extension1-Specification-Version: 1.0 extension1-Implementation-Version: 0.8 extension1-Implementation-Vendor: WROX Press Ltd extension1-Implementation-Vendor-Id: com.wrox extension1-Implementation-URL: http://www.wrox.com/extension1/

For high quality jboss hosting services please check jboss web hosting website.

Chapter 7: Web Application Confi guration The WEB-INF

Sunday, March 29th, 2009

Chapter 7: Web Application Confi guration The WEB-INF Directory The contents of the WEB-INF directory are also shown Figure 7-1 . As shown, it has a deployment descriptor (web.xml) and three subdirectories. These subdirectories include the following: . The classesdirectory . The libdirectory . The tags directory The classes Directory The classes directory contains servlet and utility classes, including JavaBeans. It may also contain a number of resource files such as key/value message lists, which contain error messages and user prompts for the application, and application-specific configuration information. Each class is stored within a directory hierarchy that matches its fully qualified name (FQN). Therefore, a class with package structure com.wrox.db.DatabaseServlet will be stored in the classes/com/ wrox/db directory structure. Because servlets are merely Java classes that implement a specified interface, they are stored in the classes directory, too. Previously, it was common to place servlets in an additional directory within the WEB-INF directory named servlets. Classes placed into this directory are no longer on the class path by default, and they need to be moved into the classesdirectory. Ideally, an administrator need not be concerned with the contents of the classes directory. However, it is worth noting that configuration files may be present in it. The resource files mentioned earlier may be within this directory and are typically text files that contain configuration information or are used to externalize error messages. This is merely a programming practice, and you may have any kind of file here. For example, there may be an ApplicationResources.propertiesfile (the name is determined by the application developer) that looks like the following: prompt.username=User Name (your email address) prompt.password=Please enter you password error.password.mismatch=The password is incorrect. Please try again. This type of list enables an application developer to refer to the text by its name (for example, prompt .username), thereby enabling an administrator to change the values, minimizing the need to touch the sensitive JSP code. The Java classes and property files placed in the classes directory are accessible only by that Web application. Earlier Tomcat versions allowed classes shared across web applications to be placed in /shared/classes, but this is no longer the case. The tags Directory An optional tags directory within the WEB-INF directory contains configuration files for tag libraries. A tag library is a group of Java classes that define the functionality of dynamic markup tags. For example, you can use a tag that you define as follows:

For reliable and cheap web hosting services please check javaweb hosting website.

Chapter 7: Web Application Confi guration By arbitrary,

Saturday, March 28th, 2009

Chapter 7: Web Application Confi guration By arbitrary, we do not mean that they can be placed anywhere and the server will find them. Rather, as long as the files are put within the Web application directory, and outside of the WEB-INF directory, then the application itself (and its designer) decides where files are placed. In the example Web application shown in Figure 7-1 , index.jspis the default welcome page for the Web application. The welcome page is the Web page served up when you access the Web application URL in this case, http://localhost:8080/exampleapp/. If this Web page were not present, then, by default, index.htmland index.htm are looked for and served. These welcome pages are subject to configuration and can be modified, as you will see later in the chapter. Besides index.jspand contact.html, the other public resources in the example application are the image files in the imagesdirectory. URL Mappings In most cases, when you request a Web resource from your browser (such as an HTML page), it is served to you without modification by the Web server. JSP pages are an exception to this. A JSP page is first passed through a JSP compiler that compiles the file to a Java file, and then compiles the Java file to a Servlet class. This Servlet class then executes, and the output is displayed on your browser. The code that makes this happen is a URL mapping defined using a element, as shown next. This URL mapping is defined in /conf/web.xml. This file is the deployment descriptor for all the Web applications individual Web applications can define their own deployment descriptors. jsp *.jsp The preceding code specifies that any URL that ends in .jspshould be passed to a servlet named jsp that is defined elsewhere in the same /conf/web.xmlconfiguration file. The definition for this servlet is as follows: jsp org.apache.jasper.servlet.JspServlet3 As you can see, the fully qualified name of the servlet is org.apache.jasper.servlet.JspServlet. The servlet is handed the request, uses the context path to load the JSP page, and passes it to Tomcat s JSP compiler, known as Jasper. The load-on-startup option ensures that the Servlet class is loaded into memory on startup with a priority of 3 (where 1 is most important) to ensure that it is loaded before any JSP pages are requested. You ll see other configuration options in the web.xml, too, and these are explained in greater detail later in this chapter.

For high quality java hosting services please check java web hosting website.

Chapter 7: Web Application Confi guration located in

Friday, March 27th, 2009

Chapter 7: Web Application Confi guration located in a directory called exampleapp, and can be accessed by the URL http://localhost:8080/ exampleapp/. Here, /exampleapp/is called the context path for the Web application. The context path refers to everything in the URL after the server and port number, and is the part of the URL that is used to resolve the location of the resource. webapps/ exampleapp/ index.jspcontact.htmlimages/ META-INF/ WEB-INF/ photo.jpg graphic.png web.xml classes/ SampleServlet.class lib/ struts.jar tags/ Figure 7-1: Directory structure for a sample Web application An exception to this is the ROOT Web application, which is installed under /webapps/ ROOT. No context path needs to be specified for the ROOT Web application, as shown in the following URL: http://localhost:8080/ In terms of the structure of the Web application, the minimum that is required is a WEB-INFdirectory with a web.xml file in it. As discussed previously in Chapter 2 , HTML and JSP pages belong to the public resources that a client may request directly. All the contents of the WEB-INFand META-INFdirectories fall into the category of an application s private resources, and cannot be accessed directly by client applications. Public Resources Everything outside the WEB-INFand META-INF directories are public resources, and can be accessed via an appropriate URL. For example, the contact.htmlfile can be accessed as follows: http://localhost:8080/exampleapp/contact.html The placement of publicly accessible files (such as JSP and HTML pages, CSS, and images) is arbitrary as far as the specifications for Web applications are concerned, and they can be accessed directly by a client.

For high quality website hosting services please check java web hosting website.

Web Application Configuration Web applications consist of static

Thursday, March 26th, 2009

Web Application Configuration Web applications consist of static content (such as HTML pages and images files) as well as dynamic content (such as servlets, JSPs, and Java classes). Chapter 2 briefly discussed servlets and JSPs. Although these Web applications usually are created by developers, they often require a system administrator to configure and deploy them, especially if the deployment is on a production machine. A systems administrator needs to know about a number of things in order to administer Web applications, such as the structure of a Web application and its configuration files. This chapter describes the configuration-related issues for Web applications: . The structure and content of a Web application . The deployment descriptor for a Web application (that is, the web.xmlconfiguration file) Chapter 8 discusses other administrative activities for Web applications (for example, deploying, undeploying, and listing Web applications). Understanding the Contents of a Web Application Web applications are usually installed under the /webapps directory. The Servlet 2.5 specification requires that a certain basic directory structure be followed. Figure 7-1 shows a sample Web application structure. The Web application is typically deployed in a directory named after the Web application. This name is also used in the Web application URL. For example, the sample Web application in Figure 7-1 is

If you looking for unlimited one inclusive web hosting plan please check unlimited web hosting website.

Chapter 6: Advanced Tomcat Features . JNDI provides

Thursday, March 26th, 2009

Chapter 6: Advanced Tomcat Features . JNDI provides a uniform interface to different directory services. This makes it possible to write only one set of lookup code across different directory services. Examples presented included the configuration of JNDI resources (such as JDBC connections and JavaMail sessions). . Lifecycle listeners are Java code modules and are configured as XML subelements of a Tomcat component. Configured listeners are invoked by the component during well-defined points in the lifecycle of a component. In Tomcat 6, lifecycle listeners are used to create manageable objects (MBeans) for supporting Tomcat manageability (via JMX), to turn on and off native code implementation of the SSL engine via APR, and to initialize the Jasper 2 JSP processor. Chapter 7 discusses the configuration for Web applications installed in the Tomcat container.

For reliable and cheap web hosting services please check javaweb hosting website.

Chapter 6: Advanced Tomcat Features The actual use

Wednesday, March 25th, 2009

Chapter 6: Advanced Tomcat Features The actual use of APR requires the download and installation of a native APR DLL. Configuration of the AprLifecycleListener will cause Tomcat 6 to attempt to find this DLL. However, if the DLL does not exist, Tomcat 6 will still be functional, but without the APR optimizations. Initialization of the JSP Processor The JSP processor in Tomcat 6 is initialized by the following line in the server.xmlfile: This JSP processor engine is a new engine that supports JSP 2.0 specification and its code name is Jasper 2. The previous listener configuration has no attributes, and simply provides an early initialization opportunity for the JSP processor prior to loading of any Web applications. Early initialization tasks include setting up a security management hook, and the initialization of an optional pool for JSP (configurable via the org.apache.jasper.runtime.JspFactoryImpl.USE_POOL system property, shown in Chapter 21 ). The actual JSP processor is a servlet, org.apache.jasper.servlet.JspServlet. This servlet is configured in the Tomcat 6 global deployment descriptor web.xml under the conf directory. Configuration of this JSP processor servlet is discussed in Chapter 5 where the system global web.xmlis explored. Summary This chapter discussed Tomcat configuration topics that are beyond the basic up-and-running requirements. The following important areas were covered: . The Access Log Valve can enable logging of resource access at different levels: the Web application, the virtual host, or globally across all the virtual hosts. This Valve is highly configurable, and you can customize the name as well as the actual format of the log entries, although the commonformat is the best known. . The standard Single Sign-on Valve enhances the user experience because users no longer must type in a username and password every time they switch between Web applications running on the same host. This Valve caches the credentials on the server and passes them between the applications as required. . The Request Filter Valves are easily configured to control all incoming requests that are to be processed or blocked entirely. These valves can block a list of IP addresses or host names. . The lesser-known Request Dumper Valve can be used to debug other valves and/or components, and to visualize the effects of scoping. . The configurable Persistent Session Manager component can be used to provide a measure of reliability to Tomcat. It can periodically back up sessions on disk, and also swap out dormant sessions to make room for active sections. Most important, it will restore sessions from disk when it starts up. This enables sessions to persist between restarts of the Tomcat server.

For high quality java hosting services please check tomcat web hosting website.