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

📄 passdata.jsp

📁 IBM RSA下的JSF开发示例
💻 JSP
字号:

<%-- tpl:insert page="/template/jsfTemplate.jtpl" --%><!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">

<%@page language="java" contentType="text/html; charset=ISO-8859-1"
	pageEncoding="ISO-8859-1"%>
<%@taglib uri="http://java.sun.com/jsf/core" prefix="f"%>
<%@taglib uri="http://java.sun.com/jsf/html" prefix="h"%>
<%@taglib uri="http://www.ibm.com/jsf/html_extended" prefix="hx"%>
<HTML>
<HEAD>
<META http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<META name="GENERATOR" content="IBM Software Development Platform">
<META http-equiv="Content-Style-Type" content="text/css">
<LINK href="../theme/Master.css" rel="stylesheet" type="text/css">
<LINK href="../theme/new.css" rel="stylesheet">
<LINK rel="stylesheet" type="text/css" href="../theme/stylesheet.css" title="Style">
<%-- tpl:put name="headarea" --%>
			<title>passData.jsp</title>
		<%-- /tpl:put --%>
<LINK rel="stylesheet" type="text/css" href="/JSFandSDO/theme/stylesheet.css" title="Style">
</HEAD>

<f:view>
	<BODY>
		<TABLE class="title" cellpadding="0">
			<TBODY>
				<TR>
					<TD class="noBorder" background="../images/gradient.jpg"
						align="CENTER"><IMG border="0" src="../images/title.jpg"></TD>
				</TR>
				<TR>
					<TD class="noBorder" align="RIGHT"><A href="/JSFandSDO">Return to Main Menu</A></TD>
				</TR>
			</TBODY>
		</TABLE>
		<%-- tpl:put name="bodyarea" --%>

<hx:scriptCollector id="scriptCollector1">

		<h:form styleClass="form" id="form1">
			
			<H2>Passing Data Using Request and Session Scopes</H2>
			<P>This sample consists of six input fields where    data
			can be entered and     passed to another JSF page using a Request Scope
			variable, a Session Scope variable, and a managed JavaBean in Session
			Scope. This sample also demonstrates how to access and modify the data
			when the page is submitted and the difference between Forwarding and
			Redirecting to a new page.<BR>
			</P>
			<TABLE cellpadding="3">
				<TBODY>
					<TR>
						<TD class="tdColor25"><B>Enter  text to be passed in Request Scope Variable:<BR>
						</B><h:inputText styleClass="inputText" id="text1" value="#{requestScope.requestText}"></h:inputText></TD>
						<TD class="td75">This text is  stored in a <B>Request Scope
						Variable</B> so that it can be passed to the next page.
						<BLOCKQUOTE>
						<P class="code">Example:<BR>
						&lt;h:inputText styleClass=&quot;inputText&quot; id=&quot;text1&quot;
						value=&quot;#{requestScope.requestText}&quot;&gt;<BR>
						&lt;/h:inputText&gt;</P></BLOCKQUOTE>
						Request Scope variables   are only persisted from the time an HTTP request is created until the response is sent back from the server.  An advantage of using request scope is that it is less intensive on the server because the data does not need to be persisted between requests.</TD>
					</TR>
					<TR>
						<TD class="tdColor25"><B>Enter  text to be passed in Session Scope Variable:</B><BR>
						<h:inputText styleClass="inputText" id="text2" value="#{sessionScope.sessionText}"></h:inputText></TD>
						<TD class="td75">This text is  stored in a <B>Session Scope
						Variable</B> so that it can be passed to the next page.
						<BLOCKQUOTE>
						<P class="code">Example:<BR>
						&lt;h:inputText styleClass=&quot;inputText&quot;
						id=&quot;text2&quot;
						value=&quot;#{sessionScope.sessionText}&quot;&gt;<BR>
						&lt;/h:inputText&gt;</P>
						</BLOCKQUOTE>
						Session Scope variables are persisted between pages for the entire length of a user's session. This is simpler to use, but puts a higher load on the server as it needs to store all the user entered information.
						<BR>
						<BR>This text will also be accessed and modified when the page is
						submitted.</TD>
					</TR>
					<TR>
						<TD class="td75" colspan="2" align="center"><B>The following four
						input fields  store the entered text into a Session Scoped
						backing JavaBean to pass the data to the next page.</B></TD>
					</TR>
					<TR>
						<TD class="tdColor25"><B>Enter First Name:</B><BR>
						<h:inputText id="text3" value="#{pc_PassData.customerBean.firstName}" styleClass="inputText">
						</h:inputText></TD>
						<TD class="td75">
						<BLOCKQUOTE>
						<P class="code">Example:<BR>
						&lt;h:inputText id=&quot;text3&quot;
						value=&quot;#{pc_PassData.customerBean.firstName}&quot;
						styleClass=&quot;inputText&quot;&gt; <BR>
						&lt;/h:inputText&gt;</P>
						</BLOCKQUOTE>
						</TD>
					</TR>
					<TR>
						<TD class="tdColor25"><B>Enter Last Name:</B><BR>
						<h:inputText id="text5" value="#{pc_PassData.customerBean.lastName}" styleClass="inputText">
						</h:inputText></TD>
						<TD class="td75">
						<BLOCKQUOTE>
						<P class="code">Example:<BR>
						&lt;h:inputText id=&quot;text5&quot;
						value=&quot;#{pc_PassData.customerBean.lastName}&quot;
						styleClass=&quot;inputText&quot;&gt;<BR>
						&lt;/h:inputText&gt;</P>
						</BLOCKQUOTE>
						</TD>
					</TR>
					<TR>
						<TD class="tdColor25"><B>Enter State:</B><BR>
						<h:inputText id="text8" value="#{pc_PassData.customerBean.state}" styleClass="inputText">
						</h:inputText></TD>
						<TD class="td75">
						<BLOCKQUOTE>
						<P class="code">Example:<BR>
						&lt;h:inputText id=&quot;text8&quot;
						value=&quot;#{pc_PassData.customerBean.state}&quot;
						styleClass=&quot;inputText&quot;&gt;<BR>
						&lt;/h:inputText&gt;</P>
						</BLOCKQUOTE>
						</TD>
					</TR>
					<TR>
						<TD class="tdColor25"><B>Enter Zip:</B><BR>
						<h:inputText id="text9" value="#{pc_PassData.customerBean.zip}" styleClass="inputText">
						</h:inputText></TD>
						<TD class="td75">
						<BLOCKQUOTE>
						<P class="code">Example:<BR>
						&lt;h:inputText id=&quot;text9&quot;
						value=&quot;#{pc_PassData.customerBean.zip}&quot;
						styleClass=&quot;inputText&quot;&gt;<BR>
						&lt;/h:inputText&gt;</P>
						</BLOCKQUOTE>
						</TD>
					</TR>
					<TR>
						<TD class="tdColor25"><hx:commandExButton id="button1" styleClass="commandExButton2" type="submit" value="Forward" action="#{pc_PassData.passDataForwardAction}">
						</hx:commandExButton> or <hx:commandExButton type="submit" value="Redirect" styleClass="commandExButton2" id="button2" action="#{pc_PassData.passDataRedirectAction}"></hx:commandExButton></TD>
						<TD class="td75">Forward: All data in the HTTP Request  is forwarded to the resulting page. Your request scope variable will
						appear on the next page. Forwards  are generally used when you are passing data with Request Scope.<BR>
						<BR>
						Redirect: All data in  the current Request Scope is lost when a page is
						redirected. Your Request Scope variable will not be available in
						the resulting page, while Session Scope variables  remain valid. When you use Redirect the URL in the browser address will be that of the resulting page, allowing a user to bookmark that page.</TD>
					</TR>
				</TBODY>
			</TABLE><H4>How it works:</H4>
			Information stored in Request Scope is only valid from the time an HTTP request is submitted until the response is sent back to the client, whereas Session Scope  remains valid during the entire length of a user's session.<BR>
			<BR>
			To create new Request or Session Scope Variable:<BR>1.  Right-click in the Page Data view and select New -&gt; Scripting Variable. <BR>2. Select the type of variable you want to create.<BR>3. Enter a name and select a data type.<BR>
			<BR>
			To create a managed Session Scoped JavaBean:<BR>1.  Right-click in the Page Data View and select New -&gt; JavaBean. <BR>2. Select &quot;Make this JavaBean Reusable&quot;.<BR>3.    Set the scope to Session.<BR>
			<BR>
			To bind input fields to variables or JavaBeans:<BR>1. From the Page Data view,  drag a data object  onto an input component. <BR>2. Optionally, add a value binding to a component by entering a value in the &quot;Value&quot; field in the Properties view.<BR>
			<BR>When a command-button is pressed an action event takes place and all field values are stored into the variables or JavaBeans they are bound to. To move to a new page  you need to set up a navigation rule. <BR>
					<BR>1. Open the Properties view of a command-button.<BR>2. Add new navigation rules and enter the page to navigate to when an action is performed.<BR>3. Enter a return String value in the button's action method to be used by the navigation rules.<BR>4. Select whether you want to use Page Forward or Page Redirect to move to a new page<BR>
			<BR>
To access and modify the values stored in JSF Scope Variables, use the following code examples:<BLOCKQUOTE>
			<P class="code">Action Method Example:<BR>
			getRequestScope().get( &quot;name of variable&quot;);<BR>
			getSessionScope().get( &quot;name of variable&quot;);<BR>
			putRequestScope().put( &quot;name of variable&quot;,
			&quot;value&quot;);<BR>
			putSessionScope().put(&quot;name of variable&quot;,
			&quot;value&quot;);<BR>
			<BR>JSTL Expression Example:<BR>requestScope.name;<BR>sessionScope.name;
			</P></BLOCKQUOTE>To view the action methods of the Forward or Redirect button, open the Quick Edit view and you  can see an example of the session variable being modified.<H4>Files
			of Interest:</H4>
			<B></B><UL>
				<LI><B>WebContent/passData/passData.jsp</B> - (This Page) This is where the JSF
				form is created and input fields are bound to the scope variables
				and session bean.</LI>
				<LI><B>WebContent/passData/passDataResult.jsp</B> - This is where
				the passed data is displayed.</LI>
				<LI><B>src/pagecode.passData.PassData.java</B> - Where the action for
				the form is located and where the request variable is modified.</LI>
				<LI><B>src/com.ibm.samples.passData.customerBean.java</B> - The managed
				Session Scope JavaBean.</LI>
			</UL>
		</h:form>
	</hx:scriptCollector>
		
		
		<%-- /tpl:put --%>
		<TABLE class="title" cellpadding="0">
			<TBODY>
				<TR>
					<TD class="noBorder" align="RIGHT"><A href="/JSFandSDO">Return to Main Menu</A></TD>
				</TR>
			</TBODY>
		</TABLE>
	</BODY>
</f:view>

</HTML><%-- /tpl:insert --%>

<%-- jsf:pagecode language="java" location="/src/pagecode/passData/PassData.java" --%><%-- /jsf:pagecode --%>

⌨️ 快捷键说明

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