⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 webapp6.html

📁 j2eePDF格式的电子书
💻 HTML
字号:
<?xml version="1.0" encoding="ISO-8859-1"?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">  <head>    <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1" />    <meta http-equiv="Content-Style-Type" content="text/css" />    <title>Deploying Web Modules</title>    <link rel="StyleSheet" href="document.css" type="text/css" media="all" />    <link rel="StyleSheet" href="catalog.css" type="text/css" media="all" />    <link rel="Table of Contents" href="J2EETutorialTOC.html" />    <link rel="Previous" href="WebApp5.html" />    <link rel="Next" href="WebApp7.html" />    <link rel="Index" href="J2EETutorialIX.html" />  </head>  <body>    <table width="550" summary="layout" id="SummaryNotReq1">      <tr>	<td align="left" valign="center">	<font size="-1">	<a href="http://java.sun.com/j2ee/1.4/download.html#tutorial" target="_blank">Download</a>	<br>	<a href="http://java.sun.com/j2ee/1.4/docs/tutorial/information/faq.html" target="_blank">FAQ</a>	<br>	<a href="http://java.sun.com/j2ee/1.4/docs/tutorial/information/history.html" target="_blank">History</a>	</td>        <td align="center" valign="center"><a accesskey="p" href="WebApp5.html"><img id="LongDescNotReq1" src="images/PrevArrow.gif" width="26" height="26" border="0" alt="Prev" /></a><a accesskey="c" href="J2EETutorialFront.html"><img id="LongDescNotReq1" src="images/UpArrow.gif" width="26" height="26" border="0" alt="Home" /></a><a accesskey="n" href="WebApp7.html"><img id="LongDescNotReq3" src="images/NextArrow.gif" width="26" height="26" border="0" alt="Next" /></a><a accesskey="i" href="J2EETutorialIX.html"></a>        </td>	<td align="right" valign="center">	<font size="-1">	<a href="http://java.sun.com/j2ee/1.4/docs/api/index.html" target="_blank">API</a>	<br>	<a href="http://java.sun.com/j2ee/1.4/docs/tutorial/information/search.html" target="_blank">Search</a>	<br>	<a href="http://java.sun.com/j2ee/1.4/docs/tutorial/information/sendusmail.html" target="_blank">Feedback</a></font>	</font>	</td>      </tr>    </table>    <img src="images/blueline.gif" width="550" height="8" ALIGN="BOTTOM" NATURALSIZEFLAG="3" ALT="Divider">    <blockquote><a name="wp214195"> </a><h2 class="pHeading1">Deploying Web Modules</h2><a name="wp214196"> </a><p class="pBody">You can deploy a Web module to the J2EE 1.4 Application Server in several ways:</p><div class="pSmartList1"><ul class="pSmartList1"><a name="wp214197"> </a><div class="pSmartList1"><li>By pointing the J2EE 1.4 Application Server at an unpackaged Web module directory structure using <code class="cCode">asadmin</code> or the Admin Console.</li></div><a name="wp214198"> </a><div class="pSmartList1"><li>By packaging the Web module and </li></div><div class="pSmartList2"><ul class="pSmartList2"><a name="wp214199"> </a><div class="pSmartList2"><li>Copying the WAR into the <code class="cCode">&lt;</code><code class="cVariable">J2EE_HOME</code><code class="cCode">&gt;/domains/domain1/autodeploy/</code> directory.</li></div><a name="wp214200"> </a><div class="pSmartList2"><li>Using the application server Admin Console, <code class="cCode">asadmin</code>, or d<code class="cCode">eploytool</code> to deploy the WAR.</li></div></ul></div></ul></div><a name="wp214201"> </a><p class="pBody">All of these methods will be described briefly in this chapter; however, packaging and deploying using <code class="cCode">deploytool</code> will be employed throughout the tutorial.</p><a name="wp214202"> </a><h3 class="pHeading2">Setting the Context Root</h3><a name="wp214204"> </a><p class="pBody">A <em class="cEmphasis">context root </em>identifies a Web application in a J2EE application server. You specify the context root when you deploy a Web module. A context root must start with a forward slash <code class="cCode">/</code> and end with a string. </p><a name="wp214205"> </a><p class="pBody">In a packaged Web module for deployment on the J2EE 1.4 Application Server, the context root is stored in <code class="cCode">sun-web_app.xml</code>. If you package the Web application with <code class="cCode">deploytool</code>, <code class="cCode">sun-web_app.xml</code> is created automatically.</p><a name="wp214207"> </a><h3 class="pHeading2">Deploying an Unpackaged Web Module</h3><a name="wp214208"> </a><p class="pBody">It is possible to deploy a Web module without packaging it into a WAR. The advantage of this approach is that you do not need to rebuild the package every time you update a file contained in the Web module. In addition, the J2EE 1.4 Application Server automatically detects updates to JSP pages, so you don't even have to redeploy the Web module when they change. </p><a name="wp214209"> </a><p class="pBody">However, in order to deploy an unpackaged Web module, you must create the Web module directory structure and provide the Web application deployment descriptor <code class="cCode">web.xml</code>. Since this tutorial uses <code class="cCode">deploytool</code> for generating deployment descriptors, it does not document how to develop one from scratch. You can view the structure of deployment descriptors in two ways:</p><div class="pSmartList1"><ul class="pSmartList1"><a name="wp214210"> </a><div class="pSmartList1"><li>In <code class="cCode">deploytool</code>, select Tools<span style="font-family: Symbol"><img src="images/arrwrite.gif" border="0" alt="Right Arrow"></span>Descriptor Viewer<span style="font-family: Symbol"><img src="images/arrwrite.gif" border="0" alt="Right Arrow"></span>Descriptor Viewer to view <code class="cCode">web.xml</code> and Tools<span style="font-family: Symbol"><img src="images/arrwrite.gif" border="0" alt="Right Arrow"></span>Descriptor Viewer<span style="font-family: Symbol"><img src="images/arrwrite.gif" border="0" alt="Right Arrow"></span>Application Server Descriptor to view <code class="cCode">sun-web_app.xml</code>. </li></div><a name="wp214211"> </a><div class="pSmartList1"><li>Unpackage one of the WARs in <code class="cCode">&lt;</code><code class="cVariable">INSTALL</code><code class="cCode">&gt;/j2eetutorial14/examples/web/provided-wars/</code> and extract the descriptor.</li></div></ul></div><a name="wp214212"> </a><p class="pBody">Since you explicitly specify the context root when you deploy and unpackaged Web module, usually it is not necessary to provide <code class="cCode">sun-web_app.xml</code>. </p><a name="wp214213"> </a><h4 class="pHeading3">Deploying with the Admin Console</h4><div class="pSmartList1"><ol type="1" class="pSmartList1"><a name="wp214214"> </a><div class="pSmartList1"><li>Expand the Applications node.</li></div><a name="wp214215"> </a><div class="pSmartList1"><li>Select Web Applications node.</li></div><a name="wp214216"> </a><div class="pSmartList1"><li>Click the Deploy button.</li></div><a name="wp214217"> </a><div class="pSmartList1"><li>Select the No radio button next to Upload File.</li></div><a name="wp214218"> </a><div class="pSmartList1"><li>Type the full path to the Web module directory in the File or Directory field. Although the GUI gives the choice to browse to the directory, this option only applies to deploying a packaged WAR.</li></div><a name="wp214219"> </a><div class="pSmartList1"><li>Click Next.</li></div><a name="wp214220"> </a><div class="pSmartList1"><li>Type the application name.</li></div><a name="wp214221"> </a><div class="pSmartList1"><li>Type the context root.</li></div><a name="wp214222"> </a><div class="pSmartList1"><li>Select the Enabled box.</li></div><a name="wp214223"> </a><div class="pSmartList1"><li>Click the OK button.</li></div></ol></div><a name="wp214224"> </a><h4 class="pHeading3">Deploying with asadmin</h4><a name="wp214225"> </a><p class="pBody">To deploy an unpackaged Web module with <code class="cCode">asadmin</code>, open a terminal window or command prompt and execute <code class="cCode">asadmin</code> <code class="cCode">deploydir</code> <code class="cVariable">full-path-to-web-module-directory</code>.</p><a name="wp214226"> </a><p class="pBody">The <code class="cCode">build</code> task for the <code class="cCode">hello1</code> application creates a <code class="cCode">build</code> directory (including <code class="cCode">web.xml</code>) in the structure of a Web module. To deploy <code class="cCode">hello1</code> using <code class="cCode">asadmin deploydir</code>, execute: </p><div class="pPreformattedRelative"><pre class="pPreformattedRelative">asadmin deploydir --contextroot /hello1 &lt;<code class="cVariable">INSTALL</code>&gt;/j2eetutorial14/examples/web/hello1/build <a name="wp214227"> </a></pre></div><a name="wp214229"> </a><p class="pBody">After you deploy the <code class="cCode">hello1</code> application, you can run the Web application by pointing a browser at</p><div class="pPreformattedRelative"><pre class="pPreformattedRelative">http://localhost:8080/hello1<a name="wp214230"> </a></pre></div><a name="wp214234"> </a><p class="pBody">You should see the greeting form depicted in <a  href="WebApp2.html#wp64571">Figure 3-1</a>.</p><a name="wp214235"> </a><p class="pBody">A Web module is executed when a Web browser references a URL that contains the Web module's context root. Since no Web component appears in <code class="cCode">http://localhost:8080/hello1/</code>, the Web container executes the default component, <code class="cCode">index.jsp</code>. The section <a  href="WebApp11.html#wp189052">Mapping URLs to Web Components</a> describes how to specify Web components in a URL.</p><a name="wp214239"> </a><h3 class="pHeading2">Deploying a Packaged Web Module</h3><a name="wp189518"> </a><p class="pBody">If you have deployed the <code class="cCode">hello1</code> application, before proceeding with this section, undeploy the application by following one of the procedures described in <a  href="WebApp10.html#wp214809">Undeploying Web Modules</a>.</p><a name="wp214244"> </a><h4 class="pHeading3">Deploying with deploytool</h4><a name="wp214245"> </a><p class="pBody">To deploy the <code class="cCode">hello1</code> Web module with <code class="cCode">deploytool</code>:</p><div class="pSmartList1"><ol type="1" class="pSmartList1"><a name="wp214249"> </a><div class="pSmartList1"><li>Select the <code class="cCode">hello1</code> WAR you created in <a  href="WebApp5.html#wp115753">Packaging Web Modules</a>.</li></div><a name="wp214250"> </a><div class="pSmartList1"><li>Select the General tab.</li></div><a name="wp214251"> </a><div class="pSmartList1"><li>Type <code class="cCode">/hello1 i</code>n the Context Root field.</li></div><a name="wp214252"> </a><div class="pSmartList1"><li>Select File<span style="font-family: Symbol"><img src="images/arrwrite.gif" border="0" alt="Right Arrow"></span>Save.</li></div><a name="wp214253"> </a><div class="pSmartList1"><li>Select Tools<span style="font-family: Symbol"><img src="images/arrwrite.gif" border="0" alt="Right Arrow"></span>Deploy.</li></div><a name="wp214254"> </a><div class="pSmartList1"><li>Click OK.</li></div></ol></div><a name="wp214255"> </a><p class="pBody">You can use one of the following methods to deploy the WAR you packaged with <code class="cCode">deploytool</code>, or one of the WARs contained in <code class="cCode">&lt;</code><code class="cVariable">INSTALL</code><code class="cCode">&gt;/j2eetutorial14/examples/web/provided-wars/</code>.</p><a name="wp214256"> </a><h4 class="pHeading3">Deploying with the Admin Console</h4><div class="pSmartList1"><ol type="1" class="pSmartList1"><a name="wp214257"> </a><div class="pSmartList1"><li>Expand the Applications node.</li></div><a name="wp214258"> </a><div class="pSmartList1"><li>Select the Web Applications node.</li></div><a name="wp214259"> </a><div class="pSmartList1"><li>Click the Deploy button.</li></div><a name="wp214260"> </a><div class="pSmartList1"><li>Select the No radio button next to Upload File.</li></div><a name="wp214261"> </a><div class="pSmartList1"><li>Type the full path to the WAR file (or click on Browse to find it), then click the OK button.</li></div><a name="wp214262"> </a><div class="pSmartList1"><li>Click Next.</li></div><a name="wp214263"> </a><div class="pSmartList1"><li>Type the application name.</li></div><a name="wp214264"> </a><div class="pSmartList1"><li>Type the context root.</li></div><a name="wp214265"> </a><div class="pSmartList1"><li>Select the Enabled box.</li></div><a name="wp214266"> </a><div class="pSmartList1"><li>Click the OK button.</li></div></ol></div><a name="wp214267"> </a><h4 class="pHeading3">Deploying with asadmin</h4><a name="wp214268"> </a><p class="pBody">To deploy a WAR with <code class="cCode">asadmin</code>, open a terminal window or command prompt and execute <code class="cCode">asadmin</code> <code class="cCode">deploy</code> <code class="cVariable">full-path-to-war-file.</code></p>    </blockquote>   <img src="images/blueline.gif" width="550" height="8" ALIGN="BOTTOM" NATURALSIZEFLAG="3" ALT="Divider">    <table width="550" summary="layout" id="SummaryNotReq1">      <tr>	<td align="left" valign="center">	<font size="-1">	<a href="http://java.sun.com/j2ee/1.4/download.html#tutorial" target="_blank">Download</a>	<br>	<a href="http://java.sun.com/j2ee/1.4/docs/tutorial/information/faq.html" target="_blank">FAQ</a>	<br>	<a href="http://java.sun.com/j2ee/1.4/docs/tutorial/information/history.html" target="_blank">History</a>	</td>        <td align="center" valign="center"><a accesskey="p" href="WebApp5.html"><img id="LongDescNotReq1" src="images/PrevArrow.gif" width="26" height="26" border="0" alt="Prev" /></a><a accesskey="c" href="J2EETutorialFront.html"><img id="LongDescNotReq1" src="images/UpArrow.gif" width="26" height="26" border="0" alt="Home" /></a><a accesskey="n" href="WebApp7.html"><img id="LongDescNotReq3" src="images/NextArrow.gif" width="26" height="26" border="0" alt="Next" /></a><a accesskey="i" href="J2EETutorialIX.html"></a>        </td>	<td align="right" valign="center">	<font size="-1">	<a href="http://java.sun.com/j2ee/1.4/docs/api/index.html" target="_blank">API</a>	<br>	<a href="http://java.sun.com/j2ee/1.4/docs/tutorial/information/search.html" target="_blank">Search</a>	<br>	<a href="http://java.sun.com/j2ee/1.4/docs/tutorial/information/sendusmail.html" target="_blank">Feedback</a></font>	</font>	</td>      </tr>    </table>    <img src="images/blueline.gif" width="550" height="8" ALIGN="BOTTOM" NATURALSIZEFLAG="3" ALT="Divider"><p><font size="-1">All of the material in <em>The J2EE(TM) 1.4 Tutorial</em> is <a href="J2EETutorialFront2.html">copyright</a>-protected and may not be published in other workswithout express written permission from Sun Microsystems.</font>  </body></html>

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -