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

📄 webapp11.html

📁 j2eePDF格式的电子书
💻 HTML
📖 第 1 页 / 共 2 页
字号:
<?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>Configuring 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="WebApp10.html" />    <link rel="Next" href="WebApp12.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="WebApp10.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="WebApp12.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="wp64678"> </a><h2 class="pHeading1">Configuring Web Modules</h2><a name="wp214867"> </a><p class="pBody">Web applications are configured via elements contained in the Web application deployment descriptor. The <code class="cCode">deploytool</code> utility generates the descriptor when you create a WAR and adds elements when you create Web components and associated classes. You can modify the elements via the inspectors associated with the WAR.</p><a name="wp83519"> </a><p class="pBody">The following sections give a brief introduction to the Web application features you will usually want to configure. A number of security parameters can be specified; these are covered in <a  href="Security4.html#wp299872">Web-Tier Security</a>.</p><a name="wp80194"> </a><p class="pBody">In the following sections, some examples demonstrate procedures for configuring the Hello, World application. If Hello, World does not use a specific configuration feature, the section gives references to other examples that illustrate how to specify the deployment descriptor element and describes generic procedures for specifying the feature using <code class="cCode">deploytool</code>. Extended examples that demonstrate how to use <code class="cCode">deploytool</code> are in <a  href="Servlets3.html#wp63984">The Example Servlets</a>, <a  href="JSPIntro3.html#wp83415">The Example JSP Pages</a>, and <a  href="JSTL2.html#wp83467">The Example JSP Pages</a>.</p><a name="wp189052"> </a><h3 class="pHeading2">Mapping URLs to Web Components</h3><a name="wp189053"> </a><p class="pBody">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. A URL path contains the context root and an alias:</p><div class="pPreformattedRelative"><pre class="pPreformattedRelative">http://<em class="cEmphasis">host</em>:<code class="cVariable">port</code>/<code class="cVariable">context_root</code>/<code class="cVariable">alias</code><a name="wp219218"> </a></pre></div><a name="wp219219"> </a><h4 class="pHeading3">Setting the Component Alias</h4><a name="wp219220"> </a><p class="pBody">The <em class="cEmphasis">alias</em> identifies the Web component that should handle a request. The alias path must start with a forward slash <code class="cCode">/</code> and end with a string or a wildcard expression with an extension (<code class="cCode">*.jsp</code>, for example). Since Web containers automatically map an alias that ends with <code class="cCode">*.jsp</code>, 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. To set up the mappings for the servlet version of the <code class="cCode">hello</code> application with <code class="cCode">deploytool</code>, first package it:</p><div class="pSmartList1"><ol type="1" class="pSmartList1"><a name="wp214936"> </a><div class="pSmartList1"><li>In a terminal window, go to <code class="cCode">&lt;</code><code class="cVariable">INSTALL</code><code class="cCode">&gt;/j2eetutorial14/examples/web/hello2/</code>.</li></div><a name="wp214937"> </a><div class="pSmartList1"><li>Run <code class="cCode">asant</code> <code class="cCode">build</code>. This target will compile the servlets to the <code class="cCode">&lt;</code><code class="cVariable">INSTALL</code><code class="cCode">&gt;/j2eetutorial14/examples/web/hello2/build/</code> directory. </li></div><a name="wp214938"> </a><div class="pSmartList1"><li>Start <code class="cCode">deploytool</code>.</li></div><a name="wp214939"> </a><div class="pSmartList1"><li>Create a Web application called <code class="cCode">hello2</code> by running the New Web Component Wizard. Select File<span style="font-family: Symbol"><img src="images/arrwrite.gif" border="0" alt="Right Arrow"></span>New<span style="font-family: Symbol"><img src="images/arrwrite.gif" border="0" alt="Right Arrow"></span>Web Component.</li></div><a name="wp214940"> </a><div class="pSmartList1"><li>New Web Component Wizard</li></div><div class="pSmartList2"><ol type="a" class="pSmartList2"><a name="wp214941"> </a><div class="pSmartList2"><li>Select the Create New Stand-Alone WAR Module radio button.</li></div><a name="wp214942"> </a><div class="pSmartList2"><li>In the WAR Location field, enter <code class="cCode">&lt;</code><code class="cVariable">INSTALL</code><code class="cCode">&gt;/j2eetutorial14/examples/web/hello2/hello2.war</code>. </li></div><a name="wp214943"> </a><div class="pSmartList2"><li>In the WAR Name field, enter <code class="cCode">hello2</code>.</li></div><a name="wp214944"> </a><div class="pSmartList2"><li>In the Context Root field, enter <code class="cCode">/hello2</code>.</li></div><a name="wp214945"> </a><div class="pSmartList2"><li>Click Edit to add the content files.</li></div><a name="wp214946"> </a><div class="pSmartList2"><li>In the Edit Contents dialog, navigate to <code class="cCode">&lt;</code><code class="cVariable">INSTALL</code><code class="cCode">&gt;/j2eetutorial14/examples/web/hello2/build/</code>. Select <code class="cCode">duke.waving.gif</code> and the <code class="cCode">servlets</code> package and click Add. Click OK.</li></div><a name="wp214947"> </a><div class="pSmartList2"><li>Click Next.</li></div><a name="wp214948"> </a><div class="pSmartList2"><li>Select the Servlet radio button. </li></div><a name="wp214949"> </a><div class="pSmartList2"><li>Click Next.</li></div><a name="wp214950"> </a><div class="pSmartList2"><li>Select <code class="cCode">GreetingServlet</code> from the Servlet Class combo box. </li></div><a name="wp214951"> </a><div class="pSmartList2"><li>Click Finish.</li></div></ol></div><a name="wp214952"> </a><div class="pSmartList1"><li>Select File<span style="font-family: Symbol"><img src="images/arrwrite.gif" border="0" alt="Right Arrow"></span>New<span style="font-family: Symbol"><img src="images/arrwrite.gif" border="0" alt="Right Arrow"></span>Web Component.</li></div><div class="pSmartList2"><ol type="a" class="pSmartList2"><a name="wp214953"> </a><div class="pSmartList2"><li>Click the Add to Existing WAR Module radio button and select <code class="cCode">hello2</code> from the combo box. Since the WAR contains all of the servlet classes, you do not have to add any more content.</li></div><a name="wp214954"> </a><div class="pSmartList2"><li>Click Next.</li></div><a name="wp214955"> </a><div class="pSmartList2"><li>Select the Servlet radio button. </li></div><a name="wp214956"> </a><div class="pSmartList2"><li>Click Next.</li></div><a name="wp214957"> </a><div class="pSmartList2"><li>Select <code class="cCode">ResponseServlet</code> from the Servlet Class combo box. </li></div><a name="wp214958"> </a><div class="pSmartList2"><li>Click Finish.</li></div></ol></div></ol></div><a name="wp214959"> </a><p class="pBody">Then, to set the aliases, </p><div class="pSmartList1"><ol type="1" class="pSmartList1"><a name="wp214960"> </a><div class="pSmartList1"><li>Select the <code class="cCode">GreetingServlet</code> Web component.</li></div><a name="wp214961"> </a><div class="pSmartList1"><li>Select the Aliases tab. </li></div><a name="wp214962"> </a><div class="pSmartList1"><li>Click Add to add a new mapping.</li></div><a name="wp214963"> </a><div class="pSmartList1"><li>Type <code class="cCode">/greeting</code> in the aliases list.</li></div><a name="wp214964"> </a><div class="pSmartList1"><li>Select the <code class="cCode">ResponseServlet</code> Web component.</li></div><a name="wp214965"> </a><div class="pSmartList1"><li>Click Add.</li></div><a name="wp214966"> </a><div class="pSmartList1"><li>Type <code class="cCode">/response</code> in the aliases list.</li></div><a name="wp214967"> </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></ol></div><a name="wp85892"> </a><h3 class="pHeading2">Declaring Welcome Files</h3><a name="wp85893"> </a><p class="pBody">The <em class="cEmphasis">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 class="cEmphasis">valid partial request)</em> that is not mapped to a Web component. </p>

⌨️ 快捷键说明

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