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

📄 attr.htm

📁 这个压缩包里的都是超级经典的java例子
💻 HTM
字号:
<HTML>
<HEAD>
<META http-equiv="Content-Type" content="text/html; charset=UTF-8">
<TITLE>Saving Data Using JSTL in a JSP Page (Java Developers Almanac Example)
</TITLE>
<META CONTENT="Patrick Chan" NAME="AUTHOR">
<META CONTENT="Code Examples from The Java Developers Almanac 1.4" NAME="DESCRIPTION">
<META CONTENT="Addison-Wesley/Patrick Chan" NAME="OWNER">
<META CONTENT="3/20/02" NAME="revision">
<META CONTENT="no-cache" HTTP-EQUIV="Pragma">
<LINK href="/almanac.css" media="screen" type="text/css" rel="stylesheet">
</HEAD>
<BODY>
<TABLE CELLSPACING="0" CELLPADDING="0" BORDER="0">
<TR>
<TD></TD>
</TR>
</TABLE>
<br>
<TABLE CELLSPACING="0" CELLPADDING="0" BORDER="0">
<TR>
<TD></TD>
</TR>
<TR>
<TD rowspan="3"><A HREF="/?l=ex"><IMG BORDER="0" ALIGN="BOTTOM" HSPACE="10" SRC="/egs/almanac14a.jpg"></A></TD><TD VALIGN="top">
<h1>The Java Developers Almanac 1.4</h1>
<br>
        Order this book from <a href="/cgi-bin/scripts/redirect.pl?l=ex&url=http://www.amazon.com/exec/obidos/ASIN/0201752808/xeo">Amazon</a>.
    </TD>
</TR>
<TR>
<TD align="right" valign="bottom">
<FORM method="get" action="/cgi-bin/search/find.pl">
<INPUT size="25" name="words" type="text"><INPUT value="Search" type="submit">
</FORM>
</TD>
</TR>
</TABLE>
<HR color="#6666cc">
<TABLE CELLSPACING="0" CELLPADDING="0" BORDER="0">
<TR>
<TD valign="top"><script type="text/javascript">
<!--
google_ad_client = "pub-6001183370374757";
google_ad_width = 120;
google_ad_height = 600;
google_ad_format = "120x600_as";
google_ad_channel = "4777242811";
google_ad_type = "text_image";
google_color_border = "FFFFFF";
google_color_bg = "FFFFFF";
google_color_link = "6666CC";
google_color_url = "6666CC";
google_color_text = "000000";
//--></script><script src="http://pagead2.googlesyndication.com/pagead/show_ads.js" type="text/javascript"></script></TD><TD>&nbsp;&nbsp;&nbsp;</TD><TD valign="top">
<DIV ALIGN="LEFT">
<A HREF="/">Home</A>
    &gt;
    <A HREF="../index.html">List of Packages</A>
    &gt;

    
    <B><A HREF="../javax.servlet.jsp.jstl.core/pkg.html">javax.servlet.jsp.jstl.core</A></B><font color="#666666" class="xsmall-font">
        &nbsp;[6 examples]
    </font>
</DIV><P>
  <h3>e1067. Saving Data Using JSTL in a JSP Page</h3>

When a JSP page needs to save data for its processing, it must
specify a location, called the <font color="#0066ff"><i>scope</i></font>. See
<a href="../javax.servlet.jsp/attr.html" class="eglink"><b>e1048</b> Saving Data in a JSP Page</a> for an explanation of the four
available scopes.

<P> Data is saved using a mechanism called scoped variables.  A
scoped variable has a name, which is of type <code>String</code> and a value,
which is of type <code>Object</code>.  For non-page scoped variables, it is
recommended that the name use the reverse domain name convention
(e.g., prefixed with com_mycompany) to minimize unexpected collisions
when integrating with third party modules.

<P> When using the JSTL's expression language (see
<a href="../javax.servlet.jsp.jstl.core/uselang.html" class="eglink"><b>e1065</b> Enabling the JSTL Expression Language in a JSP Page</a>), the variables in each
scope are made available in the implicit objects <code>pageScope</code>,
<code>requestScope</code>, <code>sessionScope</code>, and <code>applicationScope</code>.

<P> This example saves and retrieves values in scoped variables in
each of the four scopes:


<pre>    &lt;%-- Declare the core library --%&gt;
    &lt;%@ taglib uri="/WEB-INF/tld/c.tld" prefix="c" %&gt;
    
    &lt;%-- Save data in scoped variables --%&gt;
    &lt;c:set var="name1" value="value1" scope="page" /&gt;
    &lt;c:set var="com_mycompany_name2" value="value2" scope="request" /&gt;
    &lt;c:set var="com_mycompany_name3" value="value3" scope="session" /&gt;
    &lt;c:set var="com_mycompany_name4" value="value4" scope="application" /&gt;
    
    &lt;%-- Show the saved values --%&gt;
    &lt;c:out value='${pageScope.name1}' /&gt;
    &lt;c:out value='${requestScope.com_mycompany_name2}' /&gt;
    &lt;c:out value='${sessionScope.com_mycompany_name3}' /&gt;
    &lt;c:out value='${applicationScope.com_mycompany_name4}' /&gt;
</pre>

When retrieving a saved value, it is possible to omit the scope.  If
the scope is omitted, the variable name is automatically searched for
in each of the scopes, in the order <code>pageScope</code>,
<code>requestScope</code>, <code>sessionScope</code>, and <code>applicationScope</code>.


<pre>    &lt;%-- Show the saved values without a specific scope --%&gt;
    &lt;c:out value='${name1}' /&gt;
    &lt;c:out value='${com_mycompany_name2}' /&gt;
    &lt;c:out value='${com_mycompany_name3}' /&gt;
    &lt;c:out value='${com_mycompany_name4}' /&gt;
</pre>

It is also possible to specify the value to save using the contents
of the body, rather than through the <code>value</code> attribute:


<pre>    &lt;%-- Save data using body content --%&gt;
    &lt;c:set var="name1" scope="page"&gt;
        value 1 in body
    &lt;/c:set&gt;
    &lt;c:set var="com_mycompany_name2" scope="request" &gt;
        value 2 in body
    &lt;/c:set&gt;
    &lt;c:set var="com_mycompany_name3" scope="session" &gt;
        value 3 in body
    &lt;/c:set&gt;
    &lt;c:set var="com_mycompany_name4" scope="application"&gt;
        value 4 in body
    &lt;/c:set&gt;
</pre>

When specifying the value using body contents, the body contents
is first trimmed of leading and trailing white space before it is
saved. For example, 


<pre>    &lt;c:set var="name1" scope="page"&gt;
        line 1
        line 2
    &lt;/c:set&gt;
</pre>
would be saved as:

<pre>    "line 1\n    line 2"
</pre>
<P><table width="600" CELLSPACING="0" CELLPADDING="2" BORDER="0">
<tr>
<td bgcolor="#6666cc" align="center"><font color="#ffffff">
            &nbsp;<b>Related Examples</b></font></td>
</tr>
</table>


e1064. <a class="eglink" href="usejstl.html?l=rel">
    Using the Java Standard Tag Library (JSTL) in a JSP Page
</a>
<br>

e1065. <a class="eglink" href="uselang.html?l=rel">
    Enabling the JSTL Expression Language in a JSP Page
</a>
<br>

e1066. <a class="eglink" href="getparam.html?l=rel">
    Getting a Request Parameter Using JSTL in a JSP Page
</a>
<br>

e1068. <a class="eglink" href="htmlfrag.html?l=rel">
    Saving and Emitting HTML Fragments Using JSTL in a JSP Page
</a>
<br>

e1069. <a class="eglink" href="if.html?l=rel">
    Conditionally Generating Output Using JSTL in a JSP Page
</a>
<br>


<br>

<br>
<FONT class="xsmall-font">
&copy; 2002 Addison-Wesley.
</FONT></TD><TD>&nbsp;&nbsp;&nbsp;</TD><TD valign="top"><A href="http://compositesw.com/devzone?ref=javaalmanac"><IMG alt="Click Here" height="600" width="120" border="0" src="/csw_oad_120x600_final.gif"></A></TD>
</TR>
</TABLE>
</BODY>
<HEAD>
<META http-equiv="Content-Type" content="text/html; charset=UTF-8">
<META CONTENT="NO-CACHE" HTTP-EQUIV="PRAGMA">
</HEAD>
</HTML>

⌨️ 快捷键说明

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