Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Typical Struts2 workflow (bear in mind that Struts2 is extremely configurable, its parts are well decoupled)</p> <p><code>struts.xml</code> => defines 'mappings' :</p> <ul> <li>which <code>action</code> is executed for each URL </li> <li>one or more <code>results</code> : which resource (typically a JSP) generates the view for each result returned by the action</li> </ul> <p>Hence, for example, say a <code>struts.xml</code> contains</p> <pre><code> &lt;action name="add" class="example.SumAction"&gt; &lt;result name="error"&gt;/Error.jsp&lt;/result&gt; &lt;result name="success"&gt;/SumResult.jsp&lt;/result&gt; &lt;/action&gt; </code></pre> <p>And your Java action is:</p> <pre><code> public class SumAction { private int x; private int x; private int z; // getters and setters ommited public String execute() { z = x + y; return "success"; } } </code></pre> <p>Then the request <code>http://mysite.com/mywebapp/add.action?x=10&amp;y=20</code> would make Struts2 to instantiate a <code>SumAction</code> object, set the <code>x</code> and <code>y</code> properties and call the <code>execute</code> method. If "success" is returned, then it will place the action in some "scope", forward to "/SumResult.jsp" in which typically one use some struts2 tag to show the result, pulling it from the action object.</p> <pre><code> Result: &lt;b&gt;&lt;s:property value="z" /&gt;&lt;/b&gt; </code></pre> <p>Of course, in less trivial scenarios the <code>execute()</code> method would call the service layer.</p> <p>So, it's not very clear if the action is controller or controller+model, I'd say the later, because it not only has the logic to process the request but also acts as a container of the data (input and result). But only during the scope of a request.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload