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

📄 jspintro2.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>What Is a JSP Page?</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="JSPIntro.html" />    <link rel="Next" href="JSPIntro3.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="JSPIntro.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="JSPIntro3.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="wp65749"> </a><h2 class="pHeading1">What Is a JSP Page?</h2><a name="wp65751"> </a><p class="pBody">A <em class="cEmphasis">JSP page</em> is a text document that contains two types of text: static template data, which can be expressed in any text-based format, such as <a  href="http://www.w3.org/MarkUp" target="_blank">HTML</a>, <a  href="http://www.w3.org/TR/SVG" target="_blank">SVG</a>, <a  href="http://www.oasis-open.org/cover/wap-wml.html" target="_blank">WML</a>, and <a  href="http://www.w3.org/TR/REC-xml" target="_blank">XML,</a> and JSP elements, which construct dynamic content. </p><a name="wp94783"> </a><p class="pBody">The recommended file extension for the source file of a JSP page is <code class="cCode">.jsp</code>. The page may be composed of a top file that includes other files that contain either a complete JSP page or a fragment of a JSP page. The recommended extension for the source file of a fragment of a JSP page is <code class="cCode">.jspf</code>.</p><a name="wp84375"> </a><p class="pBody">The JSP elements in a JSP page can be expressed in two syntaxes--standard and XML--though any given file can only use one syntax. A JSP page in XML syntax is an XML document and can be manipulated by tools and APIs for XML documents. This chapter and chapters <a  href="JSTL.html#wp74644"></a> through <a  href="JSPAdvanced.html#wp65706">16</a> document only the standard syntax. The JSP XML syntax is covered in Chapter <a  href="JSPX.html#wp114886">13</a>. A syntax card and reference that summarizes both syntaxes is available at</p><div class="pPreformattedRelative"><pre class="pPreformattedRelative"><a  href="http://java.sun.com/products/jsp/docs.html#syntax" target="_blank">http://java.sun.com/products/jsp/docs.html#syntax</a><a name="wp65757"> </a></pre></div><a name="wp84418"> </a><h3 class="pHeading2">Example</h3><a name="wp65758"> </a><p class="pBody">The Web page in <a  href="JSPIntro2.html#wp72152">Figure 12-1</a> is a form that allows you to select a locale and displays the date in a manner appropriate to the locale.</p><a name="wp72145"> </a><p class="pBody"></p><div align="left"><img src="images/Fig27.gif" height="186" width="447" alt="Localized Date Form" border="0" hspace="0" vspace="0"/></div><p class="pBody"></p><p>  <a name="72152"> </a><strong><font >Figure 12-1    Localized Date Form</font></strong></p><a name="wp72131"> </a><p class="pBody">The source code for this example is in the <code class="cCode">&lt;</code><code class="cVariable">INSTALL</code><code class="cCode">&gt;/j2eetutorial14/examples/web/date/</code> directory. The JSP page, <code class="cCode"><a  href="../examples/web/date/web/index.txt" target="_blank">index.jsp</a></code>, used to create the form appears below; it is a typical mixture of static HTML markup and JSP elements. If you have developed Web pages, you are probably familiar with the HTML document structure statements (<code class="cCode">&lt;head&gt;</code>, <code class="cCode">&lt;body&gt;</code>, and so on) and the HTML statements that create a form (<code class="cCode">&lt;form&gt;)</code> and a menu (<code class="cCode">&lt;select&gt;)</code>. </p><a name="wp72136"> </a><p class="pBody">The lines in bold in the example code contain the following types of JSP constructs:</p><div class="pSmartList1"><ul class="pSmartList1"><a name="wp65766"> </a><div class="pSmartList1"><li>A page directive (<code class="cCodeBold">&lt;%@page ... %&gt;</code>) sets the content type returned by the page.</li></div><a name="wp72822"> </a><div class="pSmartList1"><li>Tag library directives (<code class="cCodeBold">&lt;%@taglib ... %&gt;</code>) import custom tag libraries.</li></div><a name="wp65767"> </a><div class="pSmartList1"><li><code class="cCodeBold">jsp:useBean</code> creates an object containing a collection of locales and initializes an identifier that points to that object.</li></div><a name="wp65769"> </a><div class="pSmartList1"><li>JSP expression language expressions (<code class="cCodeBold">${ }</code>) retrieve the value of object properties. The value of an are used to set tag attribute values.</li></div><a name="wp72780"> </a><div class="pSmartList1"><li>Custom tags set a variable (<code class="cCodeBold">c:set</code>), iterate over a collection of locale names (<code class="cCodeBold">c:forEach)</code>, and conditionally insert HTML text into the response (<code class="cCodeBold">c:if</code>, <code class="cCodeBold">c:choose</code>, <code class="cCodeBold">c:when</code>, <code class="cCodeBold">c:otherwise</code>).</li></div><a name="wp73973"> </a><div class="pSmartList1"><li><code class="cCodeBold">jsp:setProperty</code> sets the value of an object property.</li></div><a name="wp72868"> </a><div class="pSmartList1"><li>A function (<code class="cCodeBold">f:equals</code>) tests the equality of an attribute and the current item of a collection. (Note: a built-in <code class="cCode">==</code> operator is usually used to test equality). </li></div><div class="pPreformattedRelative"><pre class="pPreformattedRelative">&lt;%@ <code class="cCodeBold">page contentType</code>=&quot;text/html; charset=UTF-8&quot; %&gt;&lt;%@ <code class="cCodeBold">taglib</code> uri=&quot;<code class="cCode">http://java.sun.com/jsp/jstl/core</code>&quot; &nbsp;&nbsp;&nbsp;&nbsp;prefix=&quot;c&quot; %&gt;&lt;%@ <code class="cCodeBold">taglib</code> uri=&quot;/functions&quot; prefix=&quot;f&quot; %&gt;&lt;html&gt;&lt;head&gt;&lt;title&gt;Localized Dates&lt;/title&gt;&lt;/head&gt;&lt;body bgcolor=&quot;white&quot;&gt;&lt;<code class="cCodeBold">jsp:useBean</code> id=&quot;locales&quot; scope=&quot;application&quot;&nbsp;&nbsp;class=&quot;mypkg.MyLocales&quot;/&gt;&lt;form name=&quot;localeForm&quot; action=&quot;index.jsp&quot; method=&quot;post&quot;&gt;&lt;<code class="cCodeBold">c:set</code> var=&quot;selectedLocaleString&quot; value=&quot;<code class="cCodeBold">${param.locale}</code>&quot; /&gt;&lt;<code class="cCodeBold">c:set</code> var=&quot;selectedFlag&quot; &nbsp;&nbsp;value=&quot;<code class="cCodeBold">${!empty selectedLocaleString}</code>&quot; /&gt;&lt;b&gt;Locale:&lt;/b&gt;&lt;select name=locale&gt;&lt;<code class="cCodeBold">c:forEach</code> var=&quot;localeString&quot; items=&quot;<code class="cCodeBold">${locales.localeNames}</code>&quot; &gt;&lt;<code class="cCodeBold">c:choose</code>&gt;&nbsp;&nbsp;&lt;<code class="cCodeBold">c:when</code> test=&quot;<code class="cCodeBold">${selectedFlag}</code>&quot;&gt;

⌨️ 快捷键说明

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