|
Struts example source code file (jsp_3.jsp)
The Struts jsp_3.jsp source code
<%
request.setAttribute("decorator", "none");
response.setHeader("Cache-Control","no-cache"); //HTTP 1.1
response.setHeader("Pragma","no-cache"); //HTTP 1.0
response.setDateHeader ("Expires", 0); //prevents caching at the proxy server
%>
<p>
<b>set tag
</p>
<p>
The <i>set tag sets the variable with the name specified in the name attribute to
the value specified in the <i>value attribute in the scope
entered in the <i>scope attribute. The available scopes are:
<ul>
<li>application - application scope according to servlet spec
<li>session - session scope according to servlet spec
<li>request - request scope according to servlet spec
<li>page - page scope according to servlet sepc
<li>action - the value will be set in the request scope and Struts' action context
</ul>
</p>
<p>
This example sets <i>favouriteBand in the request scope to the first element of the bands property:
</p>
<p>
<pre id="example0">
<s:set name="favouriteBand" value="bands[0]" />
<s:property value="#favouriteBand" />
</pre>
</p>
<p>
<a href="#" onclick="execJSP('example0')">Do it for me
</p>
<p>
<b>url tag
</p>
<p>
The <i>url tag is used to build urls (who would have guessed!). To build an url mapping to
an action, set the <i>namespace and action attributes. The url will be stored under
the name specified in the <i>id attribute. url tag uses the id attribute while
the <i>set tag uses name. To specify a value (no action lookup), just use the value
attribute. <i>param tags can be nested inside the url tag to add parameters to the url.
</p>
<p>
First link creates a url that maps to an action, second one creates a url to google, passing one parameter:
</p>
<p>
<pre id="example1">
<s:url id="evalAction" namespace="/nodecorate" action="jspEval" />
<s:a href="%{#evalAction}" >Eval</s:a>
<s:url id="google" value="http://www.google.com" >
<s:param name="q" value="%{'Struts 2'}" />
</s:url>
<s:a href="%{#google}" >Eval</s:a>
</pre>
</p>
<p>
<a href="#" onclick="execJSP('example1')">Do it for me
</p>
<p>
<a href="#" onclick="window.open('http://struts.apache.org/2.x/docs/set.html')">[More on the set tag]
<a href="#" onclick="window.open('http://struts.apache.org/2.x/docs/url.html')">[More on the url tag]
</p>
Other Struts examples (source code examples)Here is a short list of links related to this Struts jsp_3.jsp source code file: |
| ... this post is sponsored by my books ... | |
#1 New Release! |
FP Best Seller |
Copyright 1998-2024 Alvin Alexander, alvinalexander.com
All Rights Reserved.
A percentage of advertising revenue from
pages under the /java/jwarehouse
URI on this website is
paid back to open source projects.