Author: lukaszlenart
Date: Wed Jun 28 15:49:47 2017
New Revision: 1014670
Log:
Updates production
Modified:
websites/production/struts/content/core-developers/ajax.html
websites/production/struts/content/core-developers/nutshell.html
Modified: websites/production/struts/content/core-developers/ajax.html
==============================================================================
--- websites/production/struts/content/core-developers/ajax.html (original)
+++ websites/production/struts/content/core-developers/ajax.html Wed Jun 28
15:49:47 2017
@@ -125,169 +125,147 @@
<a href="index.html" title="back to Core Developers Guide"><< back to Core
Developers Guide</a>
<h1 id="ajax">AJAX</h1>
-<p>AJAX is an acronym for Asynchronous JavaScript and XML. Essentially, a
JavaScript can make a HTTP request and update portions of a page directly,
without going through a conventional POST or GET and refreshing the entire
page. Better yet, a page can contain several JavaScripts making simultaneous
(asynchronous) requests.</p>
-
-<p>The key point is that when a script makes an âAjax requestâ (XHR), the
server doesnât know it came from a script, and handles it like any other
request. One reason Ajax is so successful is that it works just fine with
existing server technologies, including Struts.</p>
-
-<p>Itâs not the Ajax request that is different, but the Ajax response.
Instead of returning an entire page for the browser to display (or redisplay),
an Ajax response will just return a portion of a page. The response can take
the form of XML, or HTML, or plain text, another script, or whatever else the
calling script may want.</p>
-
-<p>Both Struts 1 and Struts 2 can return any type of response. We are not
limited to forwarding to a server page. In Struts 1, you can just do something
like:</p>
-
-<div class="highlighter-rouge"><pre
class="highlight"><code>response.setContentType("text/html");
-PrintWriter out = response.getWriter();
-out.println("Hello World! This is an AJAX response from a Struts Action.");
-out.flush();
-return null;
-
+<p>AJAX is an acronym for Asynchronous JavaScript and XML. Essentially, a
JavaScript can make a HTTP request and update
+portions of a page directly, without going through a conventional POST or GET
and refreshing the entire page.
+Better yet, a page can contain several JavaScripts making simultaneous
(asynchronous) requests.</p>
+
+<p>The key point is that when a script makes an âAjax requestâ (XHR), the
server doesnât know it came from a script,
+and handles it like any other request. One reason Ajax is so successful is
that it works just fine with existing server
+technologies, including Struts.</p>
+
+<p>Itâs not the Ajax request that is different, but the Ajax response.
Instead of returning an entire page for the browser
+to display (or redisplay), an Ajax response will just return a portion of a
page. The response can take the form of XML,
+or HTML, or plain text, another script, or whatever else the calling script
may want.</p>
+
+<p>Both Struts 1 and Struts 2 can return any type of response. We are not
limited to forwarding to a server page.
+In Struts 1, you can just do something like:</p>
+
+<div class="highlighter-rouge"><pre class="highlight"><code><span
class="n">response</span><span class="o">.</span><span
class="na">setContentType</span><span class="o">(</span><span
class="s">"text/html"</span><span class="o">);</span>
+<span class="n">PrintWriter</span> <span class="n">out</span> <span
class="o">=</span> <span class="n">response</span><span class="o">.</span><span
class="na">getWriter</span><span class="o">();</span>
+<span class="n">out</span><span class="o">.</span><span
class="na">println</span><span class="o">(</span><span class="s">"Hello World!
This is an AJAX response from a Struts Action."</span><span class="o">);</span>
+<span class="n">out</span><span class="o">.</span><span
class="na">flush</span><span class="o">();</span>
+<span class="k">return</span> <span class="kc">null</span><span
class="o">;</span>
</code></pre>
</div>
<p>In Struts 2, we can do the same thing with a Stream result.</p>
-<table>
- <tbody>
- <tr>
- <td>Using a Struts 2 plugin (e.g., <em>JSON plugin</em> , jQuery plugin,
etc.) is, in general, preferred to writing the response directly from within an
action. See sections following this for further details.</td>
- </tr>
- </tbody>
-</table>
-
-<table>
- <tbody>
- <tr>
- </tr>
- </tbody>
-</table>
+<blockquote>
+ <p>Using a Struts 2 plugin (e.g., <em>JSON plugin</em> , jQuery plugin,
etc.) is, in general, preferred to writing the response
+directly from within an action. See sections following this for further
details.</p>
+</blockquote>
<p><strong>Struts 2 Stream result Action</strong></p>
-<div class="highlighter-rouge"><pre class="highlight"><code>package actions;
-
-import java.io.InputStream;
-import java.io.StringBufferInputStream;
-import com.opensymphony.xwork2.ActionSupport;
-
-public class TextResult extends ActionSupport {
- private InputStream inputStream;
- public InputStream getInputStream() {
- return inputStream;
- }
-
- public String execute() throws Exception {
- inputStream = new ByteArrayInputStream("Hello World! This is a text
string response from a Struts 2 Action.".getBytes("UTF-8"));
- return SUCCESS;
- }
-}
+<div class="highlighter-rouge"><pre class="highlight"><code><span
class="kn">package</span> <span class="n">actions</span><span class="o">;</span>
+<span class="kn">import</span> <span
class="nn">java.io.InputStream</span><span class="o">;</span>
+<span class="kn">import</span> <span
class="nn">java.io.StringBufferInputStream</span><span class="o">;</span>
+<span class="kn">import</span> <span
class="nn">com.opensymphony.xwork2.ActionSupport</span><span class="o">;</span>
+
+<span class="kd">public</span> <span class="kd">class</span> <span
class="nc">TextResult</span> <span class="kd">extends</span> <span
class="n">ActionSupport</span> <span class="o">{</span>
+ <span class="kd">private</span> <span class="n">InputStream</span> <span
class="n">inputStream</span><span class="o">;</span>
+ <span class="kd">public</span> <span class="n">InputStream</span> <span
class="n">getInputStream</span><span class="o">()</span> <span
class="o">{</span>
+ <span class="k">return</span> <span class="n">inputStream</span><span
class="o">;</span>
+ <span class="o">}</span>
+
+ <span class="kd">public</span> <span class="n">String</span> <span
class="n">execute</span><span class="o">()</span> <span
class="kd">throws</span> <span class="n">Exception</span> <span
class="o">{</span>
+ <span class="n">inputStream</span> <span class="o">=</span> <span
class="k">new</span> <span class="n">ByteArrayInputStream</span><span
class="o">(</span><span class="s">"Hello World! This is a text string response
from a Struts 2 Action."</span><span class="o">.</span><span
class="na">getBytes</span><span class="o">(</span><span
class="s">"UTF-8"</span><span class="o">));</span>
+ <span class="k">return</span> <span class="n">SUCCESS</span><span
class="o">;</span>
+ <span class="o">}</span>
+<span class="o">}</span>
</code></pre>
</div>
<p><strong>Struts 2 Configuring the TextResult Action</strong></p>
-<div class="highlighter-rouge"><pre class="highlight"><code><action
name="text-result" class="actions.TextResult">
- <result type="stream">
- <param name="contentType">text/html</param>
- <param name="inputName">inputStream</param>
- </result>
-</action>
-
+<div class="highlighter-rouge"><pre class="highlight"><code><span
class="nt"><action</span> <span class="na">name=</span><span
class="s">"text-result"</span> <span class="na">class=</span><span
class="s">"actions.TextResult"</span><span class="nt">></span>
+ <span class="nt"><result</span> <span class="na">type=</span><span
class="s">"stream"</span><span class="nt">></span>
+ <span class="nt"><param</span> <span class="na">name=</span><span
class="s">"contentType"</span><span class="nt">></span>text/html<span
class="nt"></param></span>
+ <span class="nt"><param</span> <span class="na">name=</span><span
class="s">"inputName"</span><span class="nt">></span>inputStream<span
class="nt"></param></span>
+ <span class="nt"></result></span>
+<span class="nt"></action></span>
</code></pre>
</div>
-<p>(ok) Struts 2 can also return a JSON (JavaScript Object Notation)
response, using a <a
href="http://cwiki\.apache\.org/S2PLUGINS/json\-plugin\.html">plugin</a>^[http://cwiki.apache.org/S2PLUGINS/json-plugin.html].</p>
+<blockquote>
+ <p>Struts 2 can also return a JSON (JavaScript Object Notation) response,
using a <a
href="http://cwiki.apache.org/S2PLUGINS/json-plugin.html">plugin</a>.</p>
+</blockquote>
<p>On the client side, there are two basic strategies, which can be mixed and
matched.</p>
-<p>First, you can use some type of JSP tag. Here, you donât have to know
very much at all about Ajax or JavaScript. The taglib does all the work, and
you just have to figure out how to use the taglib. The standard Struts 2 taglib
includes several <em>Ajax JSP tags</em> , and many third-party libraries are
available, including:</p>
+<p>First, you can use some type of JSP tag. Here, you donât have to know
very much at all about Ajax or JavaScript.
+The taglib does all the work, and you just have to figure out how to use the
taglib. The standard Struts 2 taglib
+includes several <em>Ajax JSP tags</em> , and many third-party libraries are
available, including:</p>
<ul>
- <li>
- <p><a href="http://ajaxtags\.sourceforge\.net/">Ajax
Tags</a>^[http://ajaxtags.sourceforge.net/]</p>
- </li>
- <li>
- <p><a href="http://javawebparts\.sourceforge\.net/">AjaxParts
Taglib</a>^[http://javawebparts.sourceforge.net/]</p>
- </li>
- <li>
- <p><a
href="http://servletsuite\.blogspot\.com/2006/06/coldtags\-suite\-ajax\-edition\.html">ColdTags
Suite</a>^[http://servletsuite.blogspot.com/2006/06/coldtags-suite-ajax-edition.html]</p>
- </li>
- <li>
- <p><a href="http://www\.jenkov\.com/prizetags/introduction\.tmpl">Prize
Tags</a>^[http://www.jenkov.com/prizetags/introduction.tmpl]</p>
- </li>
- <li>
- <p><a
href="http://json\-taglib\.sourceforge\.net/">JSON-taglib</a>^[http://json-taglib.sourceforge.net/]</p>
- </li>
+ <li><a href="http://ajaxtags.sourceforge.net/">Ajax Tags</a></li>
+ <li><a href="http://javawebparts.sourceforge.net/">AjaxParts Taglib</a></li>
+ <li><a
href="http://servletsuite.blogspot.com/2006/06/coldtags-suite-ajax-edition.html">ColdTags
Suite</a></li>
+ <li><a href="http://www.jenkov.com/prizetags/introduction.tmpl">Prize
Tags</a></li>
+ <li><a href="http://json-taglib.sourceforge.net/">JSON-taglib</a></li>
</ul>
-<p>Alternatively, you can use a plain-old Ajax widget on a plain-old HTML
page, using libraries like <a
href="http://dojotoolkit\.org/">Dojo</a>^[http://dojotoolkit.org/], <a
href="http://jquery\.com/">JQuery</a>^[http://jquery.com/], or <a
href="http://developer\.yahoo\.com/yui/">YUI</a>^[http://developer.yahoo.com/yui/],
and the StreamResult or the <a
href="http://cwiki\.apache\.org/S2PLUGINS/json\-plugin\.html">JSON
Plugin</a>^[http://cwiki.apache.org/S2PLUGINS/json-plugin.html]. Here, the
skyâs the limit, but you actually have to learn something about JavaScript as
a language.</p>
+<p>Alternatively, you can use a plain-old Ajax widget on a plain-old HTML
page, using libraries like
+<a href="http://dojotoolkit.org/">Dojo</a>, <a
href="http://jquery.com/">JQuery</a>, or <a
href="http://developer.yahoo.com/yui/">YUI</a>,
+and the StreamResult or the <a
href="http://cwiki.apache.org/S2PLUGINS/json-plugin.html">JSON Plugin</a>.
+Here, the skyâs the limit, but you actually have to learn something about
JavaScript as a language.</p>
-<p>####Ajax Plugins####</p>
+<h2 id="ajax-plugins">Ajax Plugins</h2>
<p>While Struts works fine with Ajax out-of-the-box, for added value, several
Ajax-centric plugins are available.</p>
-<p>#####Ajax Tag Plugins#####</p>
+<h3 id="ajax-tag-plugins">Ajax Tag Plugins</h3>
<ul>
- <li>
- <p><strong>jQuery</strong> - The <a
href="https://github\.com/struts\-community\-plugins/struts2\-jquery">jQuery
Plugin</a>^[https://github.com/struts-community-plugins/struts2-jquery]Â
provide ajax functionality and UI Widgets an JavaScript Grid based on the
jQuery javascript framework.**
-**</p>
- </li>
- <li>
- <p><strong>Ajax Parts</strong> - The <a
href="http://code\.google\.com/p/struts2ajaxpartstaglibplugin/">AjaxParts
Taglib (APT)</a>^[http://code.google.com/p/struts2ajaxpartstaglibplugin/] is a
component of the Java Web Parts (JWP) project (<a
href="http://javawebparts\.sourceforge\.net">http://javawebparts.sourceforge.net</a>)
that allows for 100% declarative (read: no Javascript coding required!) AJAX
functionality within a Java-based webapp.</p>
- </li>
- <li>
- <p><strong>Dojo</strong> - The <em>Ajax Tags Dojo Plugin</em> was
represented as a theme for Struts 2.0. For Struts 2.1, the Dojo tags are
bundled as a plugin until version 2.3.x. Since version 2.5 this plugin is not
part of th Struts2 distribution anymore </p>
- </li>
- <li>
- <p><strong>YUI</strong> - The <a
href="https://code\.google\.com/p/struts2yuiplugin/">Yahoo User Interface (YUI)
Plugin</a>^[https://code.google.com/p/struts2yuiplugin/] has only a few tags
are available so far, but the YUI tags tend to be easier to use than the Dojo
versions.</p>
- </li>
+ <li><strong>jQuery</strong> - The <a
href="https://github.com/struts-community-plugins/struts2-jquery">jQuery
Plugin</a> provides ajax
+functionality and UI Widgets an JavaScript Grid based on the jQuery javascript
framework.</li>
+ <li><strong>Ajax Parts</strong> - The <a
href="http://code.google.com/p/struts2ajaxpartstaglibplugin/">AjaxParts Taglib
(APT)</a> is a component
+of the Java Web Parts (JWP) project (<a
href="http://javawebparts.sourceforge.net">http://javawebparts.sourceforge.net</a>)
that
+allows for 100% declarative (read: no Javascript coding required!) AJAX
functionality within a Java-based webapp.</li>
+ <li><strong>Dojo</strong> - The <em>Ajax Tags Dojo Plugin</em> was
represented as a theme for Struts 2.0. For Struts 2.1, the Dojo tags are
+bundled as a plugin until version 2.3.x. Since version 2.5 this plugin is not
part of th Struts2 distribution anymore. </li>
+ <li><strong>YUI</strong> - The <a
href="https://code.google.com/p/struts2yuiplugin/">Yahoo User Interface (YUI)
Plugin</a> has only a few tags
+are available so far, but the YUI tags tend to be easier to use than the Dojo
versions.</li>
</ul>
-<p>#####Other Ajax Plugins#####</p>
+<h3 id="other-ajax-plugins">Other Ajax Plugins</h3>
<ul>
- <li>
- <p><strong>Ajax File Upload</strong> - With the <a
href="http://www\.davidjc\.com/ajaxfileupload/demo\!input\.action">Ajax File
Upload Plugin</a>^[http://www.davidjc.com/ajaxfileupload/demo!input.action] we
can upload a file to the server and asynchronously monitor its progress.</p>
- </li>
- <li>
- <p><strong>GWT</strong> - The <a
href="https://code\.google\.com/p/struts2gwtplugin/">Google Web Toolkit
Plugin</a>^[https://code.google.com/p/struts2gwtplugin/] exposes Struts 2
actions to the GWT RPC mechanism.</p>
- </li>
- <li>
- <p><strong>JSON</strong> - The <em>JSON Plugin</em> serializes Actions
properties into JSON, making it easy to respond to JavaScript requests.</p>
- </li>
+ <li><strong>Ajax File Upload</strong> - With the <a
href="http://www.davidjc.com/ajaxfileupload/demo!input.action">Ajax File Upload
Plugin</a>
+we can upload a file to the server and asynchronously monitor its
progress.</li>
+ <li><strong>GWT</strong> - The <a
href="https://code.google.com/p/struts2gwtplugin/">Google Web Toolkit
Plugin</a> exposes Struts 2 actions to
+the GWT RPC mechanism.</li>
+ <li><strong>JSON</strong> - The <em>JSON Plugin</em> serializes Actions
properties into JSON, making it easy to respond to JavaScript requests.</li>
</ul>
-<p>See the <a href="http://cwiki\.apache\.org/S2PLUGINS/home\.html">Struts
Plugin Repository</a>^[http://cwiki.apache.org/S2PLUGINS/home.html] for a
complete list of Struts 2 plugins.</p>
+<p>See the <a href="http://cwiki.apache.org/S2PLUGINS/home.html">Struts Plugin
Repository</a> for a complete list of Struts 2 plugins.</p>
-<p>####Ajax Results with JSP####</p>
+<h2 id="ajax-results-with-jsp">Ajax Results with JSP</h2>
-<p>While server pages are most often used to generate HTML, we can use server
pages to create other types of data streams. Hereâs an example:</p>
+<p>While server pages are most often used to generate HTML, we can use server
pages to create other types of data streams.
+Hereâs an example:</p>
<p><strong>book.jsp</strong></p>
-<div class="highlighter-rouge"><pre class="highlight"><code><%@ page
import="java.util.Iterator,
- java.util.List,
- com.esolaria.dojoex.Book,
- com.esolaria.dojoex.BookManager" %>
+<pre><code class="language-jsp"><%@ page import="java.util.Iterator,
+ java.util.List,
+ com.esolaria.dojoex.Book,
+ com.esolaria.dojoex.BookManager" %>
<%
- String bookIdStr = request.getParameter("bookId");
- int bookId = (bookIdStr == null || "".equals(bookIdStr.trim()))
- ? 0 : Integer.parseInt(bookIdStr);
- Book book = BookManager.getBook(bookId);
- if (book != null) {
- out.println(book.toJSONString());
- System.out.println("itis: " + book.toJSONString());
- }
+ String bookIdStr = request.getParameter("bookId");
+ int bookId = (bookIdStr == null || "".equals(bookIdStr.trim()))
+ ? 0 : Integer.parseInt(bookIdStr);
+ Book book = BookManager.getBook(bookId);
+ if (book != null) {
+ out.println(book.toJSONString());
+ System.out.println("itis: " + book.toJSONString());
+ }
%>
-
</code></pre>
-</div>
-
-<p>In the code example, we use</p>
-<div class="highlighter-rouge"><pre class="highlight"><code>System.out.println
-</code></pre>
-</div>
-<p>to return a JSON data stream as the response. For more about this
technique, see the article <a
href="http://today\.java\.net/pub/a/today/2006/04/27/building\-ajax\-with\-dojo\-and\-json\.html">Using
Dojo and JSON to Build Ajax
Applications</a>^[http://today.java.net/pub/a/today/2006/04/27/building-ajax-with-dojo-and-json.html].</p>
+<p>In the code example, we use <code
class="highlighter-rouge">System.out.println</code> to return a JSON data
stream as the response. For more about this
+technique, see the article <a
href="http://today.java.net/pub/a/today/2006/04/27/building-ajax-with-dojo-and-json.html">Using
Dojo and JSON to Build Ajax Applications</a>.</p>
</section>
</article>
Modified: websites/production/struts/content/core-developers/nutshell.html
==============================================================================
--- websites/production/struts/content/core-developers/nutshell.html (original)
+++ websites/production/struts/content/core-developers/nutshell.html Wed Jun 28
15:49:47 2017
@@ -125,157 +125,145 @@
<a href="index.html" title="back to Core Developers Guide"><< back to Core
Developers Guide</a>
<h1 id="nutshell">Nutshell</h1>
-<p>The framework documentation is written for active web developers and
assumes a working knowledge about how Java web applications are built. For more
about the underlying nuts and bolts, see the <a
href="http://struts\.apache\.org/primer\.html">Key Technologies
Primer</a>^[http://struts.apache.org/primer.html].</p>
+<p>The framework documentation is written for active web developers and
assumes a working knowledge about how
+Java web applications are built. For more about the underlying nuts and bolts,
see
+the <a href="../primer.html">Key Technologies Primer</a>.</p>
-<blockquote>
-
-</blockquote>
-
-<p>####Apache Struts 2 Architecture in a Nutshell####</p>
+<h2 id="apache-struts-2-architecture-in-a-nutshell">Apache Struts 2
Architecture in a Nutshell</h2>
<p><img src="attachments/struts2-arch.png" alt="struts2-arch.png" /></p>
<ol>
- <li>The web browser requests a resource (/mypage.action,
/reports/myreport.pdf, et cetera)\</li>
- <li>The Filter Dispatcher looks at the request and determines the
appropriate Action\</li>
- <li>The Interceptors automatically apply common functionality to the
request, like workflow, validation, and file upload handling\</li>
- <li>The Action method executes, usually storing and/or retrieving
information from a database\</li>
- <li>The Result renders the output to the browser, be it HTML, images, PDF,
or something else\</li>
+ <li>The web browser requests a resource - <code
class="highlighter-rouge">/mypage.action</code>, <code
class="highlighter-rouge">/reports/myreport.pdf</code>, etc</li>
+ <li>The Filter Dispatcher looks at the request and determines the
appropriate Action</li>
+ <li>The Interceptors automatically apply common functionality to the
request, like workflow, validation, and file upload handling</li>
+ <li>The Action method executes, usually storing and/or retrieving
information from a database</li>
+ <li>The Result renders the output to the browser, be it HTML, images, PDF,
or something else</li>
</ol>
-<p>|
-|ââââââââââââââââââââââââââââââââââââââââââ|ââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââ�
�ââââââââââââââââââââââââââââââââââââââââââââ-|</p>
+<h2 id="struts-tags-in-a-nutshell">Struts Tags in a nutshell</h2>
-<p>####Struts Tags in a nutshell####</p>
-
-<p>The Struts Tags help you create rich web applications with a minimum of
coding. Often, much of the coding effort in a web application goes into the
pages. The Struts Tags reduce effort by reducing code.</p>
+<p>The Struts Tags help you create rich web applications with a minimum of
coding. Often, much of the coding effort
+in a web application goes into the pages. The Struts Tags reduce effort by
reducing code.</p>
<div class="highlighter-rouge"><pre class="highlight"><code>
-<% User user = ... %>
-<form action="Profile_update.action" method="post">
- <table>
- <tr>
- <td align="right"><label>First
name:</label></td>
- <td><input type="text" name="user.firstname"
value="<%=user.getFirstname() %> /></td>
+<span class="err"><</span>% User user = ... %>
+<span class="nt"><form</span> <span class="na">action=</span><span
class="s">"Profile_update.action"</span> <span class="na">method=</span><span
class="s">"post"</span><span class="nt">></span>
+ <span class="nt"><table></span>
+ <span class="nt"><tr></span>
+ <span class="nt"><td</span> <span class="na">align=</span><span
class="s">"right"</span><span class="nt">><label></span>First
name:<span class="nt"></label></td></span>
+ <span class="nt"><td><input</span> <span
class="na">type=</span><span class="s">"text"</span> <span
class="na">name=</span><span class="s">"user.firstname"</span> <span
class="na">value=</span><span class="s">"<%=user.getFirstname() %>
/></td>
</tr>
<tr>
- <td><input type="radio" name="user.gender" value="0"
id="user.gender0"
- <% if (user.getGender()==0) { %> checked="checked" %>
} %> />
- <label for="user.gender0">Female</label>
- </tr>
- </table>
-</form>
+ <td><input type="</span><span
class="na">radio</span><span class="err">"</span> <span
class="na">name=</span><span class="s">"user.gender"</span> <span
class="na">value=</span><span class="s">"0"</span> <span
class="na">id=</span><span class="s">"user.gender0"</span>
+ <span class="err"><%</span> <span class="na">if</span>
<span class="err">(</span><span class="na">user</span><span
class="err">.</span><span class="na">getGender</span><span
class="err">()==</span><span class="na">0</span><span class="err">)</span>
<span class="err">{</span> <span class="err">%</span><span
class="nt">></span> checked="checked" %> } %> />
+ <span class="nt"><label</span> <span
class="na">for=</span><span class="s">"user.gender0"</span><span
class="nt">></span>Female<span class="nt"></label></span>
+ <span class="nt"></tr></span>
+ <span class="nt"></table></span>
+<span class="nt"></form></span>
...
-
-</code></pre>
-</div>
-
-<p>Looking over the markup, itâs easy to see why Java web development
without the aid from a modern framework is hard! So far, weâve only coded
two controls, and there are six more to go! Letâs rewrite and finish the form
using Struts Tags.</p>
-
-<p>|\
-\
-<img
src="/Users/lukaszlenart/Projects/Apache/struts\-site/target/md/attachments/att1846\_nutshell\.GIF"
alt="nutshell.GIF" />
-|\
-<s:actionerror/>\
-<s:form action=âProfile_updateâ validate=âtrueâ>\
- <s:textfield label=âUsernameâ name=âusernameâ/>\
- <s:password label=âPasswordâ name=âpasswordâ/>\
- <s:password label=â(Repeat) Passwordâ name=âpassword2â/>\
- <s:textfield label=âFull Nameâ name=âfullNameâ/>\
- <s:textfield label=âFrom Addressâ name=âfromAddressâ/>\
- <s:textfield label=âReply To Addressâ
name=âreplyToAddressâ/>\
- <s:submit value=âSaveâ name=âSaveâ/>\
- <s:submit action=âRegister_cancelâ value=âCancelâ
name=âCancelâ onclick=âform.onsubmit=nullâ/>\
-</s:form>\
- The Struts Tags also support validation and localization as first-class
features. So not only is there less code, but there is <em>more</em> utility. \
-In about the same amount of code as two conventional controls, the Struts Tags
can create an entire data-input form with eight controls. Not only is there
less code, but the code is easier to read and maintain. |
-|âââââââââââââââââââââââââââââââââââââââ|âââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââ�
�ââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââ
âââââââââââââââââââââââââââ-|</p>
-
-<p>####Struts Configuration in a Nutshell####</p>
-
-<p>A web application uses a deployment descriptor to initialize resources like
filters and listeners. The web deployment descriptor is formatted as a XML
document and named</p>
-
-<div class="highlighter-rouge"><pre class="highlight"><code>web.xml
</code></pre>
</div>
-<p>. Struts can either initialize its resources by scanning your classes using
Java packages declared in this</p>
-<div class="highlighter-rouge"><pre class="highlight"><code>web.xml
-</code></pre>
-</div>
-<p>file, or you can have full control over the configuration via a
configuration file, named</p>
-
-<div class="highlighter-rouge"><pre class="highlight"><code>struts.xml
-</code></pre>
-</div>
-<p>. These resources include action mappings, to direct input to server-side
Action classes, and result types, to select output pages.</p>
+<p>Looking over the markup, itâs easy to see why Java web development
without the aid from a modern framework is hard!
+So far, weâve only coded two controls, and there are six more to go! Letâs
rewrite and finish the form using Struts Tags.</p>
-<p>Hereâs a typical configuration (</p>
+<p><img src="attachments/att1846_nutshell.gif" alt="nutshell.gif" /></p>
-<div class="highlighter-rouge"><pre class="highlight"><code>struts.xml
+<div class="highlighter-rouge"><pre class="highlight"><code><span
class="nt"><s:actionerror/></span>
+<span class="nt"><s:form</span> <span class="na">action=</span><span
class="s">"Profile\_update"</span> <span class="na">validate=</span><span
class="s">"true"</span><span class="nt">></span>
+ <span class="nt"><s:textfield</span> <span
class="na">label=</span><span class="s">"Username"</span> <span
class="na">name=</span><span class="s">"username"</span><span
class="nt">/></span>
+ <span class="nt"><s:password</span> <span class="na">label=</span><span
class="s">"Password"</span> <span class="na">name=</span><span
class="s">"password"</span><span class="nt">/></span>
+ <span class="nt"><s:password</span> <span class="na">label=</span><span
class="s">"(Repeat) Password"</span> <span class="na">name=</span><span
class="s">"password2"</span><span class="nt">/></span>
+ <span class="nt"><s:textfield</span> <span
class="na">label=</span><span class="s">"Full Name"</span> <span
class="na">name=</span><span class="s">"fullName"</span><span
class="nt">/></span>
+ <span class="nt"><s:textfield</span> <span
class="na">label=</span><span class="s">"From Address"</span> <span
class="na">name=</span><span class="s">"fromAddress"</span><span
class="nt">/></span>
+ <span class="nt"><s:textfield</span> <span
class="na">label=</span><span class="s">"Reply To Address"</span> <span
class="na">name=</span><span class="s">"replyToAddress"</span><span
class="nt">/></span>
+ <span class="nt"><s:submit</span> <span class="na">value=</span><span
class="s">"Save"</span> <span class="na">name=</span><span
class="s">"Save"</span><span class="nt">/></span>
+ <span class="nt"><s:submit</span> <span class="na">action=</span><span
class="s">"Register_cancel"</span> <span class="na">value=</span><span
class="s">"Cancel"</span> <span class="na">name=</span><span
class="s">"Cancel"</span> <span class="na">onclick=</span><span
class="s">"form.onsubmit=null"</span><span class="nt">/></span>
+<span class="nt"></s:form></span>
</code></pre>
</div>
-<p>) for a login workflow:</p>
-
-<div class="highlighter-rouge"><pre class="highlight"><code>
-<struts>
- <package name="default" extends="struts-default">
- <action name="Logon" class="mailreader2.Logon">
- <result name="input">/pages/Logon.jsp</result>
- <result name="cancel"
type="redirectAction">Welcome</result>
- <result type="redirectAction">MainMenu</result>
- <result name="expired"
type="chain">ChangePassword</result>
- </action>
-
- <action name="Logoff" class="mailreader2.Logoff">
- <result type="redirectAction">Welcome</result>
- </action>
- </package>
-</struts>
+<p>The Struts Tags also support validation and localization as first-class
features. So not only is there less code,
+but there is <em>more</em> utility. In about the same amount of code as two
conventional controls, the Struts Tags can create
+an entire data-input form with eight controls. Not only is there less code,
but the code is easier to read and maintain.</p>
+
+<h2 id="struts-configuration-in-a-nutshell">Struts Configuration in a
Nutshell</h2>
+
+<p>A web application uses a deployment descriptor to initialize resources like
filters and listeners. The web deployment
+descriptor is formatted as a XML document and named <code
class="highlighter-rouge">web.xml</code>. Struts can either initialize its
resources by scanning
+your classes using Java packages declared in this <code
class="highlighter-rouge">web.xml</code> file, or you can have full control
over the configuration
+via a configuration file, named <code
class="highlighter-rouge">struts.xml</code>. These resources include action
mappings, to direct input to server-side
+Action classes, and result types, to select output pages.</p>
+
+<p>Hereâs a typical configuration (<code
class="highlighter-rouge">struts.xml</code>) for a login workflow:</p>
+
+<div class="highlighter-rouge"><pre class="highlight"><code><span
class="nt"><struts></span>
+ <span class="nt"><package</span> <span class="na">name=</span><span
class="s">"default"</span> <span class="na">extends=</span><span
class="s">"struts-default"</span><span class="nt">></span>
+ <span class="nt"><action</span> <span class="na">name=</span><span
class="s">"Logon"</span> <span class="na">class=</span><span
class="s">"mailreader2.Logon"</span><span class="nt">></span>
+ <span class="nt"><result</span> <span
class="na">name=</span><span class="s">"input"</span><span
class="nt">></span>/pages/Logon.jsp<span class="nt"></result></span>
+ <span class="nt"><result</span> <span
class="na">name=</span><span class="s">"cancel"</span> <span
class="na">type=</span><span class="s">"redirectAction"</span><span
class="nt">></span>Welcome<span class="nt"></result></span>
+ <span class="nt"><result</span> <span
class="na">type=</span><span class="s">"redirectAction"</span><span
class="nt">></span>MainMenu<span class="nt"></result></span>
+ <span class="nt"><result</span> <span
class="na">name=</span><span class="s">"expired"</span> <span
class="na">type=</span><span class="s">"chain"</span><span
class="nt">></span>ChangePassword<span class="nt"></result></span>
+ <span class="nt"></action></span>
+
+ <span class="nt"><action</span> <span class="na">name=</span><span
class="s">"Logoff"</span> <span class="na">class=</span><span
class="s">"mailreader2.Logoff"</span><span class="nt">></span>
+ <span class="nt"><result</span> <span
class="na">type=</span><span class="s">"redirectAction"</span><span
class="nt">></span>Welcome<span class="nt"></result></span>
+ <span class="nt"></action></span>
+ <span class="nt"></package></span>
+<span class="nt"></struts></span>
</code></pre>
</div>
-<p>(light-on) The framework provides general-purpose defaults, so we can start
using Struts right away, âout of the boxâ. Any factory defaults can be
overridden in an applicationâs configuration, as needed.</p>
+<blockquote>
+ <p>The framework provides general-purpose defaults, so we can start using
Struts right away, âout of the boxâ.
+Any factory defaults can be overridden in an applicationâs configuration, as
needed.</p>
+</blockquote>
-<p>####Struts MVC in a Nutshell####</p>
+<h2 id="struts-mvc-in-a-nutshell">Struts MVC in a Nutshell</h2>
-<p>Struts is a <a href="http://struts\.apache\.org/primer\.html\#mvc">Model
View Controller</a>^[http://struts.apache.org/primer.html#mvc] framework.
Struts provides Controller and View components, and integrates with other
technologies to provide the Model. The frameworkâs Controller acts as a
bridge between the applicationâs Model and the web View.</p>
+<p>Struts is a <a href="../primer.html#mvc">Model View Controller</a>
framework. Struts provides Controller and View components,
+and integrates with other technologies to provide the Model. The frameworkâs
Controller acts as a bridge between
+the applicationâs Model and the web View.</p>
-<p>To make it easier to present dynamic data, the framework includes a library
of markup tags. The tags interact with the frameworkâs validation and
internationalization features, to ensure that input is correct and output is
localized. The tag library can be used with JSP, FreeMarker, or Velocity. Of
course, other tag libraries, JSTL, and AJAX can also be used, with or without
the Struts tags. JavaServer Faces components are also supported.</p>
+<p>To make it easier to present dynamic data, the framework includes a library
of markup tags. The tags interact with
+the frameworkâs validation and internationalization features, to ensure that
input is correct and output is localized.
+The tag library can be used with JSP, FreeMarker, or Velocity. Of course,
other tag libraries, JSTL, and AJAX can also
+be used, with or without the Struts tags. JavaServer Faces components are also
supported.</p>
-<p>When a request is received, the Controller invokes an Action class. The
Action class examines or updates the applicationâs state by consulting the
Model (or, preferably, an interface representing the Model). To transfer data
between the Model and the View, properties can be placed on the Action class,
or on a plain old JavaBean.</p>
+<p>When a request is received, the Controller invokes an Action class. The
Action class examines or updates
+the applicationâs state by consulting the Model (or, preferably, an
interface representing the Model). To transfer
+data between the Model and the View, properties can be placed on the Action
class, or on a plain old JavaBean.</p>
-<p>Most often, the Model is represented as a graph of JavaBean objects. The
Model should do the âheavy liftingâ, and the Action will act as a
âtraffic copâ or adapter. The framework provides sophisticated, automatic
type conversion to simplify transfering data between rich domain objects and
text-only HTTP requests.</p>
+<p>Most often, the Model is represented as a graph of JavaBean objects. The
Model should do the âheavy liftingâ,
+and the Action will act as a âtraffic copâ or adapter. The framework
provides sophisticated, automatic type conversion
+to simplify transferring data between rich domain objects and text-only HTTP
requests.</p>
-<p>Struts is extensible. <em>Very</em> extensible. Every class deployed by
the framework is based on an interface. We provide all the base classes an
application may ever need, but if we missed something, itâs easy to add your
own. We provide the general-purpose framework, but you can still write
<em>your</em> application <em>your</em> way.</p>
+<p>Struts is extensible. <em>Very</em> extensible. Every class deployed by
the framework is based on an interface. We provide
+all the base classes an application may ever need, but if we missed something,
itâs easy to add your own. We provide
+the general-purpose framework, but you can still write <em>your</em>
application <em>your</em> way.</p>
-<p>####Is Struts the best choice for every project?####</p>
+<h2 id="is-struts-the-best-choice-for-every-project">Is Struts the best choice
for every project?</h2>
-<p>Apache Struts 2 helps you create an extensible development environment for
enterprise-grade applications, based on industry standards and proven design
patterns. If you need to write a very simple application, with a handful of
pages, then you might consider a âModel 1â solution that uses only server
pages.</p>
+<p>Apache Struts 2 helps you create an extensible development environment for
enterprise-grade applications, based on
+industry standards and proven design patterns. If you need to write a very
simple application, with a handful of pages,
+then you might consider a âModel 1â solution that uses only server
pages.</p>
-<p>But, if you are writing a more complicated application, with dozens of
pages, that need to be maintained over time, then Struts can help. For more
about whether Model 1 or MVC/Model 2 is right for you, see <a
href="http://www\.javaworld\.com/javaworld/jw\-12\-1999/jw\-12\-ssj\-jspmvc\.html">Understanding
JavaServer Pages Model 2
architecture</a>^[http://www.javaworld.com/javaworld/jw-12-1999/jw-12-ssj-jspmvc.html].</p>
+<p>But, if you are writing a more complicated application, with dozens of
pages, that need to be maintained over time,
+then Struts can help. For more about whether Model 1 or MVC/Model 2 is right
for you,
+see <a
href="http://www.javaworld.com/javaworld/jw-12-1999/jw-12-ssj-jspmvc.html">Understanding
JavaServer Pages Model 2 architecture</a>.</p>
-<p>####Platform Requirements####</p>
+<h2 id="platform-requirements">Platform Requirements</h2>
<p>Struts 2 requires</p>
<ul>
- <li>
- <p>Servlet API 2.4</p>
- </li>
- <li>
- <p>JSP API 2.0</p>
- </li>
- <li>
- <p>Java 5</p>
- </li>
+ <li>Servlet API 2.4</li>
+ <li>JSP API 2.0</li>
+ <li>Java 7</li>
</ul>
-<p>For a full list of requirements, including dependencies used by optional
plugins, see <a
href="http://struts\.apache\.org/2\.x/struts2\-core/dependencies\.html">Project
Dependencies</a>^[http://struts.apache.org/2.x/struts2-core/dependencies.html]</p>
-
-<p>(ok) An alternate set of JARs for Java 4 are also available. See the
âJ4â distribution.</p>
-
+<p>For a full list of requirements, including dependencies used by optional
plugins, see <a href="../maven/dependencies.html">Project Dependencies</a>.</p>
</section>
</article>