<?xml version="1.0" encoding="UTF-8"?><!-- generator="wordpress.com" -->
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	>

<channel>
	<title>web-inf &amp;laquo; WordPress.com Tag Feed</title>
	<link>http://en.wordpress.com/tag/web-inf/</link>
	<description>Feed of posts on WordPress.com tagged "web-inf"</description>
	<pubDate>Sat, 02 Jan 2010 03:07:48 +0000</pubDate>

	<generator>http://en.wordpress.com/tags/</generator>
	<language>en</language>

<item>
<title><![CDATA[Web Applications]]></title>
<link>http://shishircyb.wordpress.com/2009/10/01/web-applications/</link>
<pubDate>Thu, 01 Oct 2009 11:40:29 +0000</pubDate>
<dc:creator>Mihir Patel</dc:creator>
<guid>http://shishircyb.wordpress.com/2009/10/01/web-applications/</guid>
<description><![CDATA[A web application consists of web components, static resource files such as images, and helper class]]></description>
<content:encoded><![CDATA[<div class='snap_preview'><p>A web application consists of web components, static resource files such as images, and helper classes and libraries. In the Java 2 platform, web components provide the dynamic extension capabilities for a web server.</p>
<p><strong>Web Components :</strong></p>
<ul>
<li>Java Servlets</li>
<li>JSP</li>
<li>Web Services endpoint</li>
</ul>
<p><strong>Web Container :</strong></p>
<ul>
<li>Web components are supported by the services of a runtime platform called a web container.</li>
<li>A web container provides services such as request dispatching, security, concurrency, and life-cycle management. It also gives web components access to APIs such as naming, transactions, and email.</li>
</ul>
<p><strong>Web application deployment descriptor (DD) :</strong> The configuration information is maintained in a text file in XML format called a web application deployment descriptor.</p>
<div id="attachment_722" class="wp-caption aligncenter" style="width: 470px"><img class="size-full wp-image-722" title="Request Handling" src="http://shishircyb.wordpress.com/files/2009/09/request-handling.jpg" alt="Java Web Application Request Handling" width="460" height="304" /><p class="wp-caption-text">Java Web Application Request Handling</p></div>
<h2><strong>Java Web Application Technologies</strong></h2>
<p><strong> </strong></p>
<div id="attachment_726" class="wp-caption aligncenter" style="width: 427px"><strong><strong><img class="size-full wp-image-726" title="Web Application Technologies" src="http://shishircyb.wordpress.com/files/2009/09/web-application-technologies.jpg" alt="Java Web Application Technologies" width="417" height="173" /></strong></strong><p class="wp-caption-text">Java Web Application Technologies</p></div>
<p><strong> </strong></p>
<p><strong>Servlets</strong> are Java programming language classes that dynamically process requests and construct responses.</p>
<p>Servlets are best suited for service-oriented applications (web service endpoints are implemented as servlets) and the control functions of a presentation-oriented application, such as dispatching requests and handling nontextual data.</p>
<p>JSP pages are text-based documents that execute as servlets but allow a more natural approach to creating static content.</p>
<p>JSP pages are more appropriate for generating text-based markup such as HTML, Scalable Vector Graphics (SVG), Wireless Markup Language (WML), and XML.</p>
<h2><strong>Web Application Life Cycle</strong></h2>
<p>The process for creating, deploying, and executing a web application can be summarized as follows :</p>
<p>1.    Develop the web component code.<br />
2.    Develop the web application deployment descriptor.<br />
3.    Compile the web application components and helper classes referenced by the components.<br />
4.    Optionally package the application into a deployable unit.<br />
5.    Deploy the application into a web container.<br />
6.    Access a URL that references the web application.</p>
<h2><strong>Web Module</strong></h2>
<p><strong>Web Resources :</strong> In the Java EE architecture, web components and static web content files such as images are called web resources.</p>
<p><strong>Web Module :</strong> A web module is the smallest deployable and usable unit of web resources.</p>
<p>In addition to web components and web resources, a web module can contain other files :</p>
<ul>
<li>Server-side utility classes (database beans, shopping carts, and so on). Often these classes conform to the JavaBeans component architecture.</li>
<li>Client-side classes (applets and utility classes).</li>
</ul>
<p><strong>Structure of Web Module</strong></p>
<p>Top level directory is  &#8211; <em>Document Root</em> of the application</p>
<p><em>Document Root contains : </em></p>
<ol>
<li>JSP pages</li>
<li>Client side classes and archives</li>
<li>Static web resources, such as images</li>
<li>WEB-INF (Sub Directory) contains -
<ul>
<li><em>web.xml :</em> The web application deployment descriptor</li>
<li><em>Tag library descriptor</em> files</li>
<li><em>classes :</em> A directory that contains server-side classes: servlets, utility classes, and JavaBeans components</li>
<li><em>tags :</em> A directory that contains tag files, which are implementations of tag libraries</li>
<li><em>lib :</em> A directory that contains JAR archives of libraries called by server-side classes</li>
</ul>
</li>
</ol>
<p>If your web module <em>does not contain any servlets, filter, or listener</em> components then it <em>does not need a web application deployment descriptor</em>.</p>
<p>You can also <em>create application-specific subdirectories</em> in -</p>
<ul>
<li>document root or</li>
<li>WEB-INF/classes/ directory</li>
</ul>
<p>You can deploy <em>Web Module</em> into any web container that conforms to the Java Servlets Specification.</p>
<p>To deploy a WAR on the Application Server, the file must also contain a <em>Runtime Deployment Descriptor</em>.</p>
<p><strong>Runtime Deployment Descriptor :</strong> The runtime deployment descriptor is an <em>XML file</em> that contains information such as the <em>context root of the web application</em> and the <em>mapping of </em>the portable names of an <em>application’s resources to the Application Server’s resources</em>.</p>
<p>The Application Server web application runtime DD is named <em>sun-web.xml</em> and is located in the WEB-INF directory along with the web application DD.</p>
<div id="attachment_748" class="wp-caption aligncenter" style="width: 452px"><img class="size-full wp-image-748" title="Web Module Structure" src="http://shishircyb.wordpress.com/files/2009/10/web-module-structure.jpg" alt="Web Module Structure " width="442" height="413" /><p class="wp-caption-text">Web Module Structure </p></div>
<p><strong>Packaging Web Modules</strong><br />
To build the hello1 application with NetBeans IDE, follow these instructions :</p>
<ol>
<li>Select File?Open Project.</li>
<li>In the Open Project dialog, navigate to<em> tut-install/javaeetutorial5/examples/web/</em></li>
<li>Select the hello1 folder.</li>
<li>Select the Open as Main Project check box.</li>
<li>Click Open Project.</li>
<li>In the Projects tab, right-click the hello1 project and select Build.</li>
</ol>
<p>To build the hello1 application using the Ant utility, follow these steps:</p>
<ol>
<li>In a terminal window, go to <em>tut-install/javaeetutorial5/examples/web/hello1/</em>.</li>
<li>Type ant. This command will spawn any necessary compilations, copy files to the <em>tut-install/javaeetutorial5/examples/web/hello1/build/</em> directory, create the WAR file, and copy it to the <em>tut-install/javaeetutorial5/examples/web/hello1/dist/</em> directory.</li>
</ol>
<p><strong>Deploying a WAR File</strong><br />
<em>Context Root :</em> A context root <em>identifies a web application in a Java EE server. </em></p>
<ul>
<li>You specify the context root when you deploy a web module.</li>
<li>A context root must start with a forward slash (/) and end with a string.</li>
</ul>
<p><strong><em>Setting the Context Root :</em></strong><br />
In a packaged web module for deployment on the Application Server, the context root is <em>stored in sun-web.xml</em>.<br />
To edit the context root, do the following :</p>
<ol>
<li> Expand your project tree in the Projects pane of NetBeans IDE.</li>
<li>Expand the Web Pages and WEB-INF nodes of your project.</li>
<li>Double-click sun-web.xml.</li>
<li>In the editor pane, click Edit As XML.</li>
<li>Edit the context root, which is enclosed by the context-root element.</li>
</ol>
<p>You can deploy a WAR file to the Application Server in a 4 ways:</p>
<ul>
<li> Copying the WAR into the domain-dir/autodeploy/ directory.</li>
<li>Using the Admin Console.</li>
<li>By running asadmin or ant to deploy the WAR.</li>
<li>Using NetBeans IDE.</li>
</ul>
<p><strong><em>Deploying a Packaged Web Module</em></strong><br />
If you have deployed the hello1 application, before proceeding with this section, undeploy the application by following one of the procedures described in <a href="http://java.sun.com/javaee/5/docs/tutorial/doc/bnadx.html#bnaen">Undeploying Web Modules</a>.</p>
<p><strong><em>Deploying with the Admin Console</em></strong></p>
<ol>
<li>Expand the Applications node.</li>
<li>Select the Web Applications node.</li>
<li>Click the Deploy button.</li>
<li>Select the radio button labeled “Package file to be uploaded to the Application Server.”</li>
<li>Type the full path to the WAR file (or click on Browse to find it), and then click the OK button.</li>
<li>Click Next.</li>
<li>Type the application name.</li>
<li>Type the context root.</li>
<li>Select the Enabled box.</li>
<li>Click the Finish button.</li>
</ol>
<p><strong><em>Deploying with asadmin</em></strong><br />
To deploy a WAR with asadmin, open a terminal window or command prompt and execute<br />
=&#62; <em><strong>asadmin</strong> </em>deploy full-path-to-war-file</p>
<p><strong><em> Deploying with Ant</em></strong><br />
To deploy a WAR with the Ant tool, open a terminal window or command prompt in the directory where you built and packaged the WAR, and execute<br />
=&#62; <em><strong>ant </strong></em>deploy</p>
<p><strong><em>Deploying with NetBeans IDE</em></strong><br />
To deploy a WAR with NetBeans IDE, do the following:</p>
<ol>
<li>Select File?Open Project.</li>
<li>In the Open Project dialog, navigate to your project and open it.</li>
<li>In the Projects tab, right-click the project and select Undeploy and Deploy.</li>
</ol>
<p><strong>Testing Deployed Web Modules</strong></p>
<ul>
<li> By default, the application is deployed to host localhost on port 8080.</li>
<li>The context root of the web application is hello1 suppose.</li>
</ul>
<p>To test the application, follow these steps:</p>
<ol>
<li> Open a web browser.</li>
<li>Enter the following URL in the web address box : <em>http://localhost:8080/hello1</em></li>
<li>Enter your name, and click Submit.</li>
</ol>
<p><strong>Listing Deployed Web Modules</strong><br />
To use the Admin Console :</p>
<ol>
<li>Open the URL http://localhost:4848/asadmin in a browser.</li>
<li>Expand the nodes Applications?Web Applications.</li>
</ol>
<p>Use the asadmin command as<em><strong> asadmin</strong> </em>list-components</p>
<p><strong>Updating Web Modules</strong></p>
<ol>
<li> Recompile any modified classes.</li>
<li>If you have deployed a packaged web module, update any modified components in the WAR.</li>
<li>Redeploy the module.</li>
<li>Reload the URL in the client.</li>
</ol>
<p><strong>Dynamic Reloading</strong></p>
<ul>
<li> If dynamic reloading is enabled, you do not have to redeploy an application or module when you change its code or deployment descriptors.</li>
<li>This capability is useful in a development environment, because it allows code changes to be tested quickly.</li>
<li>Not recommended for a production environment, however, because it may degrade performance.</li>
</ul>
<p>To enable dynamic reloading, use the Admin Console:</p>
<ol>
<li> Select the Applications Server node.</li>
<li>Select the Advanced tab.</li>
<li>Check the Reload Enabled box to enable dynamic reloading.</li>
<li>Enter a number of seconds in the Reload Poll Interval field to set the interval at which applications and modules are checked for code changes and dynamically reloaded.</li>
<li>Click the Save button.</li>
</ol>
<p>In addition, to load new servlet files or reload deployment descriptor changes, you must do the following:</p>
<ol>
<li> Create an empty file named <em>.reload</em> at the root of the module :<br />
<em>domain-dir/applications/j2ee-modules/context-root/.reload</em></li>
<li>Explicitly update the .reload file’s time stamp each time you make these changes. On UNIX, execute<br />
<em><strong>touch</strong> .reload</em></li>
</ol>
<p>For JSP pages, changes are reloaded automatically at a frequency set in the Reload Poll Interval field. To disable dynamic reloading of JSP pages, set the Reload Poll Interval field value to –1.</p>
<p><strong>Undeploying Web Modules</strong><br />
To use <strong><em>NetBeans IDE</em></strong>:</p>
<ol>
<li>Ensure the Sun Java System Application Server is running.</li>
<li>In the Runtime window, expand the Sun Java System Application Server instance and the node containing the application or module.</li>
<li>Right-click the application or module and choose Undeploy.</li>
</ol>
<p>To use the <strong><em>Admin Console:</em></strong></p>
<ol>
<li> Open the URL http://localhost:4848/asadmin in a browser.</li>
<li>Expand the Applications node.</li>
<li>Select Web Applications.</li>
<li>Click the check box next to the module you wish to undeploy.</li>
<li>Click the Undeploy button.</li>
</ol>
<p>Use the <strong><em>asadmin command </em></strong>as <em>&#8220;<strong>asadmin</strong> undeploy context-root</em>&#8220;<br />
To use the <em><strong>Ant tool</strong></em>, execute the following command in the directory where you built and packaged the WAR:<br />
&#8220;<em><strong>ant </strong>undeploy&#8221;</em></p>
<h2><strong>Configuring Web Applications</strong></h2>
<p><strong>Mapping URLs to Web Components</strong><br />
When a request is received by the web container it must determine which web component should handle the request. It does so by mapping the URL path contained in the request to a web application and a web component.</p>
<p>A URL path contains the context root and an alias<br />
&#8220;<em>http://host:port/context-root/alias&#8221;</em></p>
<p><strong>The Component Alias</strong></p>
<ol>
<li>The <em>alias</em> identifies the web component that should handle a request.</li>
<li>The <em>alias path</em> must <em>start with a forward slash (/)</em> and <em>end with a string or a wildcard expression</em> with an extension (for example, *.jsp).</li>
<li>Since web containers automatically map an alias that ends with *.jsp, you do not have to specify an alias for a JSP page unless you wish to refer to the page by a name other than its file name.</li>
</ol>
<p><strong>Declaring Welcome Files</strong></p>
<ol>
<li> The <em>welcome files</em> mechanism allows you to specify a list of files that the web container will use for appending to a request for a URL (called a <em>valid partial request</em>) that is not mapped to a web component.</li>
<li>If a web container receives a valid partial request, the web container examines the welcome file list and appends to the partial request each welcome file in the order specified and checks whether a static resource or servlet in the WAR is mapped to that request URL. The web container then sends the request to the first resource in the WAR that matches.</li>
<li>If no welcome file is specified, the Application Server will use a file named index.XXX, where XXX can be html or jsp, as the default welcome file. If there is no welcome file and no file named index.XXX, the Application Server returns a directory listing.</li>
</ol>
<p>To specify a welcome file in the web application deployment descriptor, do the following:</p>
<ul>
<li> Open <em>web.xml</em></li>
<li>Specify the JSP pages using <em>welcome-file</em> elements and include these elements inside a <em>welcome-file-list</em> element. The welcome-file element defines the JSP page to be used as the welcome page.</li>
</ul>
<p><strong> Setting Initialization Parameters</strong><br />
You can pass initialization parameters to the context or to a web component.</p>
<p>To add a context parameter, do the following:</p>
<ol>
<li> Open <em>web.xml</em>.</li>
<li>Using the following elements to add a context parameter
<ul>
<li>A param-name element that specifies the context object</li>
<li>A param-value element that specifies the parameter to pass to the context object</li>
<li>A context-param element that encloses the previous two elements</li>
</ul>
</li>
</ol>
<p>To add a web component initialization parameter, do the following:</p>
<ol>
<li>Open <em>web.xml.</em></li>
<li>Using the following elements to add a context parameter
<ul>
<li>A param-name element that specifies the name of the initialization parameter</li>
<li>A param-value element that specifies the value of the initialization parameter</li>
<li>An init-param element that encloses the previous two elements</li>
</ul>
</li>
</ol>
<p><strong>Mapping Errors to Error Screens</strong><br />
When an error occurs during execution of a web application, you can have the application display a specific error screen according to the type of error.</p>
<p>To set up error mappings, do the following:</p>
<ol>
<li> Open web.xml</li>
<li>Using the following elements
<ul>
<li>An exception-type element specifying either the exception or the HTTP status code that will cause the error page to be opened.</li>
<li>A location element that specifies the name of a web resource to be invoked when the status code or exception is returned. The name should have a leading forward slash (/).</li>
<li>An error-page element that encloses the previous two elements.<br />
You can have multiple error-page elements in your deployment descriptor.</li>
</ul>
</li>
</ol>
<p><strong>Declaring a Reference to a Resource</strong></p>
<ol>
<li>The @Resource annotation is used to declare a reference to a resource such as a data source, an enterprise bean, or an environment entry.</li>
<li>This annotation is equivalent to declaring a resource-ref element in the deployment descriptor.</li>
<li>The @Resource annotation is specified on a class, method or field.</li>
<li>The container is responsible for injecting references to resources declared by the @Resource annotation and mapping it to the proper JNDI resources.</li>
</ol>
<p><strong><em> Example</em></strong></p>
<div>
<table style="height:116px;" border="0" width="297">
<tbody>
<tr>
<td><em><strong>@Resource</strong> javax.sql.DataSource catalogDS;</em></p>
<p><em>public getProductsByCategory() {<br />
// get a connection and execute the query<br />
Connection conn = catalogDS.getConnection();<br />
..</em></p>
<p><em> }</em></td>
</tr>
</tbody>
</table>
</div>
<p>If you have multiple resources that you need to inject into one component, you need to use the @Resources annotation to contain them, as shown by the following example</p>
<div>
<table style="height:94px;" border="0" width="227">
<tbody>
<tr>
<td><em><strong>@Resources</strong> ({<br />
@Resource (name=&#8221;myDB&#8221; type=java.sql.DataSource),<br />
@Resource(name=&#8221;myMQ&#8221; type=javax.jms.ConnectionFactory)<br />
})</em></td>
</tr>
</tbody>
</table>
</div>
<p><strong>Declaring a Reference to a Web Service</strong></p>
<ol>
<li> The @WebServiceRef annotation provides a reference to a web service.</li>
<li>WebServiceRef uses the wsdlLocation element to specify the URI of the deployed service’s WSDL file.</li>
</ol>
<p><em><strong>Example</strong></em></p>
<div>
<table style="height:98px;" border="0" width="297">
<tbody>
<tr>
<td><em>&#8230;<br />
import javax.xml.ws.WebServiceRef;<br />
&#8230;<br />
public class ResponseServlet extends HTTPServlet {<br />
@WebServiceRef(wsdlLocation=<br />
&#8220;http://localhost:8080/helloservice/hello?wsdl&#8221;)<br />
static HelloService service;</em></td>
</tr>
</tbody>
</table>
</div>
<p><strong>REFERENCES</strong></p>
<ol>
<li>http://java.sun.com/javaee/5/docs/tutorial/doc/geysj.html</li>
<li>http://java.sun.com/javaee/5/docs/tutorial/doc/bnadx.html</li>
<li>http://java.sun.com/javaee/5/docs/tutorial/doc/</li>
</ol>
</div>]]></content:encoded>
</item>

</channel>
</rss>
