📄 jspintro6.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>Creating Dynamic Content</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="JSPIntro5.html" /> <link rel="Next" href="JSPIntro7.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="JSPIntro5.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="JSPIntro7.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="wp66040"> </a><h2 class="pHeading1">Creating Dynamic Content</h2><a name="wp66042"> </a><p class="pBody">You create dynamic content by accessing Java programming language object properties.</p><a name="wp66043"> </a><h3 class="pHeading2">Using Objects within JSP Pages</h3><a name="wp66044"> </a><p class="pBody">You can access a variety of objects, including enterprise beans and JavaBeans components, within a JSP page. JSP technology automatically makes some objects available, and you can also create and access application-specific objects.</p><a name="wp66045"> </a><h4 class="pHeading3">Implicit Objects</h4><a name="wp66047"> </a><p class="pBody">Implicit objects are created by the Web container and contain information related to a particular request, page, session, or application. Many of the objects are defined by the Java Servlet technology underlying JSP technology and are discussed at length in Chapter <a href="Servlets.html#wp69954">11</a>. The section <a href="JSPIntro7.html#wp71043">Implicit Objects</a> explains how you access implicit objects using the JSP expression language.</p><a name="wp66153"> </a><h4 class="pHeading3">Application-Specific Objects</h4><a name="wp66154"> </a><p class="pBody">When possible, application behavior should be encapsulated in objects so that page designers can focus on presentation issues. Objects can be created by developers who are proficient in the Java programming language and in accessing databases and other services. The main way to create and use application-specific objects within a JSP page is to use JSP standard tags discussed in <a href="JSPIntro8.html#wp70711">JavaBeans Components</a> to create JavaBeans components and set their properties, and EL expressions to access their properties. You can also access JavaBeans components and other objects in scripting elements, which are described in Chapter <a href="JSPAdvanced.html#wp65706">16</a>. </p><a name="wp66170"> </a><h4 class="pHeading3">Shared Objects</h4><a name="wp66174"> </a><p class="pBody">The conditions affecting concurrent access to shared objects described in <a href="Servlets5.html#wp64386">Controlling Concurrent Access to Shared Resources</a> apply to objects accessed from JSP pages that run as multithreaded servlets. You can indicate how a Web container should dispatch multiple client requests with the following <code class="cCode">page</code> directive:</p><div class="pPreformattedRelative"><pre class="pPreformattedRelative"><%@ page isThreadSafe="true|false" %><a name="wp66176"> </a></pre></div><a name="wp66178"> </a><p class="pBody">When the <code class="cCode">isThreadSafe</code> attribute is set to <code class="cCode">true</code>, the Web container may choose to dispatch multiple concurrent client requests to the JSP page. This is the <em class="cEmphasis">default</em> setting. If using <code class="cCode">true</code>, you must ensure that you properly synchronize access to any shared objects defined at the page level. This includes objects created within declarations, JavaBeans components with page scope, and attributes of the page context object (see <a href="JSPIntro7.html#wp71043">Implicit Objects</a>).</p><a name="wp66179"> </a><p class="pBody">If <code class="cCode">isThreadSafe</code> is set to <code class="cCode">false</code>, requests are dispatched one at a time, in the order they were received, and access to page level objects does not have to be controlled. However, you still must ensure that access to attributes of the <code class="cCode">application</code> or <code class="cCode">session</code> scope objects and to JavaBeans components with application or session scope is properly synchronized. Futhermore, it is not recommended to set <code class="cCode">isThreadSafe</code> to <code class="cCode">false</code> because the JSP page's generated servlet will implement the <code class="cCode">javax.servlet.SingleThreadModel</code> interface and since the Servlet 2.4 specification deprecates <code class="cCode">SingleThreadModel</code>, the generated servlet will contain deprecated 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="JSPIntro5.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="JSPIntro7.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 + -