| <!DOCTYPE html> |
| <html lang="en"> |
| <head> |
| <meta charset="UTF-8"/> |
| <meta name="viewport" content="width=device-width, initial-scale=1.0"/> |
| <meta name="Date-Revision-yyyymmdd" content="20140918"/> |
| <meta http-equiv="Content-Language" content="en"/> |
| <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1"> |
| |
| <title>Struts 2 Blank Archetype</title> |
| |
| <link href="//fonts.googleapis.com/css?family=Source+Sans+Pro:300,400,600,700,400italic,600italic,700italic" rel="stylesheet" type="text/css"> |
| <link href="//netdna.bootstrapcdn.com/font-awesome/4.0.3/css/font-awesome.css" rel="stylesheet"> |
| <link href="/css/main.css" rel="stylesheet"> |
| <link href="/css/custom.css" rel="stylesheet"> |
| <link href="/highlighter/github-theme.css" rel="stylesheet"> |
| |
| <script src="//code.jquery.com/jquery-1.11.0.min.js"></script> |
| <script type="text/javascript" src="/bootstrap/js/bootstrap.js"></script> |
| <script type="text/javascript" src="/js/community.js"></script> |
| |
| <!-- Matomo --> |
| <script> |
| var _paq = window._paq = window._paq || []; |
| /* tracker methods like "setCustomDimension" should be called before "trackPageView" */ |
| /* We explicitly disable cookie tracking to avoid privacy issues */ |
| _paq.push(['disableCookies']); |
| _paq.push(['trackPageView']); |
| _paq.push(['enableLinkTracking']); |
| (function() { |
| var u="//analytics.apache.org/"; |
| _paq.push(['setTrackerUrl', u+'matomo.php']); |
| _paq.push(['setSiteId', '41']); |
| var d=document, g=d.createElement('script'), s=d.getElementsByTagName('script')[0]; |
| g.async=true; g.src=u+'matomo.js'; s.parentNode.insertBefore(g,s); |
| })(); |
| </script> |
| <!-- End Matomo Code --> |
| </head> |
| <body> |
| |
| <a href="https://github.com/apache/struts" class="github-ribbon"> |
| <img decoding="async" loading="lazy" style="position: absolute; right: 0; border: 0;" width="149" height="149" src="https://github.blog/wp-content/uploads/2008/12/forkme_right_red_aa0000.png?resize=149%2C149" class="attachment-full size-full" alt="Fork me on GitHub" data-recalc-dims="1"> |
| </a> |
| |
| <header> |
| <nav> |
| <div role="navigation" class="navbar navbar-default navbar-fixed-top"> |
| <div class="container"> |
| <div class="navbar-header"> |
| <button type="button" data-toggle="collapse" data-target="#struts-menu" class="navbar-toggle"> |
| Menu |
| <span class="sr-only">Toggle navigation</span> |
| <span class="icon-bar"></span> |
| <span class="icon-bar"></span> |
| <span class="icon-bar"></span> |
| </button> |
| <a href="/index.html" class="navbar-brand logo"><img src="/img/struts-logo.svg"></a> |
| </div> |
| <div id="struts-menu" class="navbar-collapse collapse"> |
| <ul class="nav navbar-nav"> |
| <li class="dropdown"> |
| <a data-toggle="dropdown" href="#" class="dropdown-toggle"> |
| Home<b class="caret"></b> |
| </a> |
| <ul class="dropdown-menu"> |
| <li><a href="/index.html">Welcome</a></li> |
| <li><a href="/download.cgi">Download</a></li> |
| <li><a href="/releases.html">Releases</a></li> |
| <li><a href="/announce-2023.html">Announcements</a></li> |
| <li><a href="http://www.apache.org/licenses/">License</a></li> |
| <li><a href="https://www.apache.org/foundation/thanks.html">Thanks!</a></li> |
| <li><a href="https://www.apache.org/foundation/sponsorship.html">Sponsorship</a></li> |
| <li><a href="https://privacy.apache.org/policies/privacy-policy-public.html">Privacy Policy</a></li> |
| </ul> |
| </li> |
| <li class="dropdown"> |
| <a data-toggle="dropdown" href="#" class="dropdown-toggle"> |
| Support<b class="caret"></b> |
| </a> |
| <ul class="dropdown-menu"> |
| <li><a href="/mail.html">User Mailing List</a></li> |
| <li><a href="https://issues.apache.org/jira/browse/WW">Issue Tracker</a></li> |
| <li><a href="/security.html">Reporting Security Issues</a></li> |
| <li><a href="/commercial-support.html">Commercial Support</a></li> |
| <li class="divider"></li> |
| <li><a href="https://cwiki.apache.org/confluence/display/WW/Migration+Guide">Version Notes</a></li> |
| <li><a href="https://cwiki.apache.org/confluence/display/WW/Security+Bulletins">Security Bulletins</a></li> |
| <li class="divider"></li> |
| <li><a href="/maven/project-info.html">Maven Project Info</a></li> |
| <li><a href="/maven/struts2-core/dependencies.html">Struts Core Dependencies</a></li> |
| <li><a href="/maven/struts2-plugins/modules.html">Plugin Dependencies</a></li> |
| </ul> |
| </li> |
| <li class="dropdown"> |
| <a data-toggle="dropdown" href="#" class="dropdown-toggle"> |
| Documentation<b class="caret"></b> |
| </a> |
| <ul class="dropdown-menu"> |
| <li><a href="/birdseye.html">Birds Eye</a></li> |
| <li><a href="/primer.html">Key Technologies</a></li> |
| <li><a href="/kickstart.html">Kickstart FAQ</a></li> |
| <li><a href="https://cwiki.apache.org/confluence/display/WW/Home">Wiki</a></li> |
| <li class="divider"></li> |
| <li><a href="/getting-started/">Getting Started</a></li> |
| <li><a href="/security/">Security Guide</a></li> |
| <li><a href="/core-developers/">Core Developers Guide</a></li> |
| <li><a href="/tag-developers/">Tag Developers Guide</a></li> |
| <li><a href="/maven-archetypes/">Maven Archetypes</a></li> |
| <li><a href="/plugins/">Plugins</a></li> |
| <li><a href="/maven/struts2-core/apidocs/index.html">Struts Core API</a></li> |
| <li><a href="/tag-developers/tag-reference.html">Tag reference</a></li> |
| <li><a href="https://cwiki.apache.org/confluence/display/WW/FAQs">FAQs</a></li> |
| <li><a href="http://cwiki.apache.org/S2PLUGINS/home.html">Plugin registry</a></li> |
| </ul> |
| </li> |
| <li class="dropdown"> |
| <a data-toggle="dropdown" href="#" class="dropdown-toggle"> |
| Contributing<b class="caret"></b> |
| </a> |
| <ul class="dropdown-menu"> |
| <li><a href="/youatstruts.html">You at Struts</a></li> |
| <li><a href="/helping.html">How to Help FAQ</a></li> |
| <li><a href="/dev-mail.html">Development Lists</a></li> |
| <li class="divider"></li> |
| <li><a href="/submitting-patches.html">Submitting patches</a></li> |
| <li><a href="/builds.html">Source Code and Builds</a></li> |
| <li><a href="/coding-standards.html">Coding standards</a></li> |
| <li><a href="/contributors/">Contributors Guide</a></li> |
| <li class="divider"></li> |
| <li><a href="/release-guidelines.html">Release Guidelines</a></li> |
| <li><a href="/bylaws.html">PMC Charter</a></li> |
| <li><a href="/volunteers.html">Volunteers</a></li> |
| <li><a href="https://gitbox.apache.org/repos/asf?p=struts.git">Source Repository</a></li> |
| <li><a href="/updating-website.html">Updating the website</a></li> |
| </ul> |
| </li> |
| <li class="apache"><a href="http://www.apache.org/"><img src="/img/apache.png"></a></li> |
| </ul> |
| </div> |
| </div> |
| </div> |
| </nav> |
| </header> |
| |
| |
| <article class="container"> |
| <section class="col-md-12"> |
| <a href="index.html" title="back to Maven Archetypes"><< back to Maven Archetypes</a> |
| <a class="edit-on-gh" href="https://github.com/apache/struts-site/edit/master/source/maven-archetypes/struts2-archetype-blank.md" title="Edit this page on GitHub">Edit on GitHub</a> |
| <h1 id="struts-2-blank-archetype">Struts 2 Blank Archetype</h1> |
| |
| <p>The Struts 2 Blank Archetype (“blank-archetype”) provides a minimal, but complete, Struts 2 application. It demonstrates some of the most basic Struts 2 concepts.</p> |
| |
| <p><strong>Features</strong></p> |
| |
| <ul> |
| <li> |
| <p>XML-based configuration, demonstrates including additional config file</p> |
| </li> |
| <li> |
| <p>Example actions</p> |
| </li> |
| <li> |
| <p>Package-level resource bundle</p> |
| </li> |
| <li> |
| <p>XML-based validation</p> |
| </li> |
| <li> |
| <p>Unit-testing</p> |
| </li> |
| </ul> |
| |
| <p class="no_toc"><strong>Contents</strong></p> |
| |
| <ul id="markdown-toc"> |
| <li><a href="#struts-2-blank-archetype" id="markdown-toc-struts-2-blank-archetype">Struts 2 Blank Archetype</a> <ul> |
| <li><a href="#creating-our-blank-archetype-project" id="markdown-toc-creating-our-blank-archetype-project">Creating Our blank-archetype Project</a> <ul> |
| <li><a href="#staging-repository" id="markdown-toc-staging-repository">Staging repository</a></li> |
| </ul> |
| </li> |
| <li><a href="#project-structure" id="markdown-toc-project-structure">Project Structure</a> <ul> |
| <li><a href="#structure-difference-from-non-maven-projects" id="markdown-toc-structure-difference-from-non-maven-projects">Structure Difference From Non-Maven Projects</a></li> |
| </ul> |
| </li> |
| <li><a href="#building-the-project" id="markdown-toc-building-the-project">Building The Project</a> <ul> |
| <li><a href="#compilation" id="markdown-toc-compilation">Compilation</a></li> |
| <li><a href="#testing" id="markdown-toc-testing">Testing</a></li> |
| <li><a href="#assembling-creating-a-war" id="markdown-toc-assembling-creating-a-war">Assembling (Creating a WAR)</a></li> |
| <li><a href="#running" id="markdown-toc-running">Running</a></li> |
| </ul> |
| </li> |
| <li><a href="#application-documentation" id="markdown-toc-application-documentation">Application Documentation</a> <ul> |
| <li><a href="#application-configuration" id="markdown-toc-application-configuration">Application Configuration</a></li> |
| <li><a href="#welcomeaction" id="markdown-toc-welcomeaction">Welcome.action</a></li> |
| <li><a href="#helloworldaction" id="markdown-toc-helloworldaction">HelloWorld.action</a></li> |
| <li><a href="#loginaction" id="markdown-toc-loginaction">Login.action</a></li> |
| </ul> |
| </li> |
| </ul> |
| </li> |
| </ul> |
| |
| <h2 id="creating-our-blank-archetype-project">Creating Our blank-archetype Project</h2> |
| |
| <p>We’ll run the following command from our project’s parent directory (this is shown using Unix-style commands).</p> |
| |
| <div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code>$ mvn archetype:generate -B \ |
| -DgroupId=tutorial \ |
| -DartifactId=tutorial \ |
| -DarchetypeGroupId=org.apache.struts \ |
| -DarchetypeArtifactId=struts2-archetype-blank \ |
| -DarchetypeVersion=<version> |
| $ ls |
| tutorial/ |
| $ cd tutorial |
| $ ls |
| pom.xml src/ |
| </code></pre></div></div> |
| |
| <p>Depending on the state of your local system you may see Maven downloading various libraries (known as “downloading the internet”, which is what it seems Maven does sometimes). Be patient – Maven is basically setting up your required libraries automatically.</p> |
| |
| <h3 id="staging-repository">Staging repository</h3> |
| |
| <p>If the above command will fail because of missing archetypes in central repository, you can try to use staging repository.</p> |
| |
| <p>Add staging repository to your settings.xml</p> |
| |
| <div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code><settings> |
| <profiles> |
| <profile> |
| <id>staging</id> |
| <repositories> |
| <repository> |
| <id>archetype</id> |
| <url>https://repository.apache.org/content/repositories/snapshots/</url> |
| <releases> |
| <enabled>true</enabled> |
| <checksumPolicy>fail</checksumPolicy> |
| </releases> |
| <snapshots> |
| <enabled>true</enabled> |
| <checksumPolicy>warn</checksumPolicy> |
| </snapshots> |
| </repository> |
| </repositories> |
| </profile> |
| </profiles> |
| </settings> |
| </code></pre></div></div> |
| |
| <p>Use <code class="language-plaintext highlighter-rouge">staging</code> profile in the command.</p> |
| |
| <div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code>mvn archetype:generate -B \ |
| -DgroupId=tutorial \ |
| -DartifactId=tutorial \ |
| -DarchetypeGroupId=org.apache.struts \ |
| -DarchetypeArtifactId=struts2-archetype-blank \ |
| -DarchetypeVersion=<version> \ |
| -Pstaging |
| </code></pre></div></div> |
| |
| <h2 id="project-structure">Project Structure</h2> |
| |
| <p>The source code structure follows the normal <a href="http://maven.apache.org/guides/introduction/introduction-to-the-standard-directory-layout">Maven directory structure</a>. The blank-archetype does not include all of the directories listed in the Maven structure reference page.</p> |
| |
| <p>Our project’s structure looks like this:</p> |
| |
| <table> |
| <thead> |
| <tr> |
| <th>Directory</th> |
| <th>Description</th> |
| </tr> |
| </thead> |
| <tbody> |
| <tr> |
| <td>src</td> |
| <td>All project source</td> |
| </tr> |
| <tr> |
| <td>src/main</td> |
| <td>Primary source directory</td> |
| </tr> |
| <tr> |
| <td>src/main/java</td> |
| <td>Java source code</td> |
| </tr> |
| <tr> |
| <td>src/main/java/tutorial</td> |
| <td>Package defined by groupId parameter</td> |
| </tr> |
| <tr> |
| <td>src/main/java/tutorial/example</td> |
| <td>The example actions from the archetype</td> |
| </tr> |
| <tr> |
| <td>src/main/resources</td> |
| <td>Resources (config, property, and validation files, and so on</td> |
| </tr> |
| <tr> |
| <td>src/main/resources/tutorial</td> |
| <td>Package defined by groupId parameter</td> |
| </tr> |
| <tr> |
| <td>src/main/resources/tutorial/example</td> |
| <td>Example property and validation files from archetype</td> |
| </tr> |
| <tr> |
| <td>src/main/webapp</td> |
| <td>Web application files (HTML, JSP, etc.)</td> |
| </tr> |
| <tr> |
| <td>src/main/webapp/WEB-INF</td> |
| <td>Typical WEB-INF folder</td> |
| </tr> |
| <tr> |
| <td>src/main/webapp/WEB-INF/example</td> |
| <td>Files from archetype</td> |
| </tr> |
| <tr> |
| <td>src/test</td> |
| <td>Test code (unit tests etc.)</td> |
| </tr> |
| <tr> |
| <td>src/test/java</td> |
| <td>Java-based test code</td> |
| </tr> |
| <tr> |
| <td>src/test/java/tutorial</td> |
| <td>Package defined by groupId parameter</td> |
| </tr> |
| <tr> |
| <td>src/test/java/tutorial/example</td> |
| <td>Test code from archetype</td> |
| </tr> |
| </tbody> |
| </table> |
| |
| <h3 id="structure-difference-from-non-maven-projects">Structure Difference From Non-Maven Projects</h3> |
| |
| <p>One big change for folks not used to the Maven structure is the separation of Java source code and resource files. For example, in a non-Maven project our directory structure might look like this:</p> |
| |
| <table> |
| <thead> |
| <tr> |
| <th>Directory</th> |
| <th>Description</th> |
| </tr> |
| </thead> |
| <tbody> |
| <tr> |
| <td>src</td> |
| <td>All project source</td> |
| </tr> |
| <tr> |
| <td>src/tutorial</td> |
| <td>Tutorial package</td> |
| </tr> |
| <tr> |
| <td>src/tutorial/example</td> |
| <td>Example package</td> |
| </tr> |
| <tr> |
| <td>src/tutorial/example/Login.java</td> |
| <td>Login action source</td> |
| </tr> |
| <tr> |
| <td>src/tutorial/example/package.properties</td> |
| <td>Resource file</td> |
| </tr> |
| <tr> |
| <td>src/tutorial/example/Login-validation.xml</td> |
| <td>Validation file</td> |
| </tr> |
| <tr> |
| <td>src/struts.xml</td> |
| <td>Struts 2 config file</td> |
| </tr> |
| <tr> |
| <td>web</td> |
| <td>Web app files</td> |
| </tr> |
| <tr> |
| <td>web/WEB-INF</td> |
| <td>Typical WEB-INF folder</td> |
| </tr> |
| <tr> |
| <td>web/index.html</td> |
| <td>An HTML file</td> |
| </tr> |
| </tbody> |
| </table> |
| |
| <p>It can take a little while to get used to, but ultimately it provides good separation of “types” of things, and becomes second-nature pretty quickly. Note that it’s possible to use a non-Maven directory layout with Maven projects, but this can be challenging at some points.</p> |
| |
| <h2 id="building-the-project">Building The Project</h2> |
| |
| <p>There are several different ways we can go about building our project, from simple compilation up to actually running the web application – all from within Maven.</p> |
| |
| <h3 id="compilation">Compilation</h3> |
| |
| <p>Running</p> |
| |
| <div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code>$ mvn compile |
| </code></pre></div></div> |
| |
| <p>will create a <code class="language-plaintext highlighter-rouge">target</code> directory containing the compiled classes. By itself this isn’t terribly useful.</p> |
| |
| <h3 id="testing">Testing</h3> |
| |
| <p>Running</p> |
| |
| <div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code>$ mvn test |
| </code></pre></div></div> |
| |
| <p>will compile the application and run the included unit tests. Blank-archetype’s unit tests are <em>not</em> extensive, but provide a simple starting point for writing more complex, application-specific tests.</p> |
| |
| <p>Once we’ve run the Maven test command we’ll notice there’s a <code class="language-plaintext highlighter-rouge">target/surefire-reports</code> directory. The <a href="http://maven.apache.org/plugins/maven-surefire-plugin/">Maven Surefire Plugin</a> is how Maven runs our unit tests. By default it will create test results in XML and text formats in the <code class="language-plaintext highlighter-rouge">target/surefire-reports</code> directory. These files can be examined to get further information regarding the failed tests.</p> |
| |
| <h3 id="assembling-creating-a-war">Assembling (Creating a WAR)</h3> |
| |
| <p>Running</p> |
| |
| <div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code>$ mvn package |
| </code></pre></div></div> |
| |
| <p>will create a WAR file in the <code class="language-plaintext highlighter-rouge">target</code> directory.</p> |
| |
| <h3 id="running">Running</h3> |
| |
| <p>We can run blank-archetype using the <a href="https://www.eclipse.org/jetty/">Jetty</a> server via the <a href="https://www.eclipse.org/jetty/documentation/current/jetty-maven-plugin">Maven Jetty Plugin</a> by executing the Jetty plugin’s <code class="language-plaintext highlighter-rouge">run</code> command:</p> |
| |
| <div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code>$ mvn jetty:run |
| </code></pre></div></div> |
| |
| <p>Once we’ve run the application we can see that it works by visiting <code class="language-plaintext highlighter-rouge">localhost:8080/tutorial/example/Welcome.action</code> as a sanity check.</p> |
| |
| <h2 id="application-documentation">Application Documentation</h2> |
| |
| <p>The application consists of a few test actions demonstrating simple validation and package-level property (resource) files. The most interesting URLs are as follows (assuming we used <code class="language-plaintext highlighter-rouge">groupId=tutorial</code>):</p> |
| |
| <table> |
| <thead> |
| <tr> |
| <th>URL</th> |
| <th>Description</th> |
| </tr> |
| </thead> |
| <tbody> |
| <tr> |
| <td>/tutorial/example/Welcome.action</td> |
| <td>Handled by wildcard mapping</td> |
| </tr> |
| <tr> |
| <td>/tutorial/example/HelloWorld.action</td> |
| <td>Handled by explicit mapping, demonstrates package-level properties</td> |
| </tr> |
| <tr> |
| <td>/tutorial/example/Login.action</td> |
| <td>Handled by explicit mapping with method wilcard (see the Login.action documentation for information regarding how to access this URL)</td> |
| </tr> |
| </tbody> |
| </table> |
| |
| <h3 id="application-configuration">Application Configuration</h3> |
| |
| <p>The default Struts 2 configuration file is contained in <code class="language-plaintext highlighter-rouge">src/main/resources/struts.xml</code>. It includes an additional configuration file, <code class="language-plaintext highlighter-rouge">src/main/resources/example.xml</code>. The application’s mappings are contained in the <code class="language-plaintext highlighter-rouge">example.xml</code> file. The <code class="language-plaintext highlighter-rouge">struts.xml</code> file sets some constants.</p> |
| |
| <p>See the <a href="/core-developers/struts-xml">struts.xml page</a> for more information about the <code class="language-plaintext highlighter-rouge">struts.xml</code> file. For more information regarding what’s contained in typical <code class="language-plaintext highlighter-rouge">struts.xml</code> files start at the <a href="/core-developers/configuration-elements">Configuration Elements page</a>, which contains links to a bunch of information. See the <a href="/core-developers/configuration-files">Configuration Files</a> page for more information regarding additional Struts 2 configuration files, including links to the files that set all the Struts 2 default configurations.</p> |
| |
| <h3 id="welcomeaction">Welcome.action</h3> |
| |
| <p>The mapping for this action is handled by a “catch-all” mapping in <code class="language-plaintext highlighter-rouge">example.xml</code>:</p> |
| |
| <div class="language-xml highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="nt"><action</span> <span class="na">name=</span><span class="s">"*"</span> <span class="na">class=</span><span class="s">"tutorial2.example.ExampleSupport"</span><span class="nt">></span> |
| <span class="nt"><result></span>/example/{1}.jsp<span class="nt"></result></span> |
| <span class="nt"></action></span> |
| </code></pre></div></div> |
| |
| <p>This mapping is the last mapping contained in <code class="language-plaintext highlighter-rouge">example.xml</code> – anything not handled by mappings appearing before it in <code class="language-plaintext highlighter-rouge">example.xml</code> will be caught by this mapping. This mapping will look for JSP files in <code class="language-plaintext highlighter-rouge">src/main/webapp/example/*.jsp</code>. Since there’s a <code class="language-plaintext highlighter-rouge">Welcome.jsp</code> in that directory, we’re all set. See the <a href="/core-developers/wildcard-mappings">Wildcard Mappings page</a> for more information on how Struts 2 can use wildcard mappings.</p> |
| |
| <h3 id="helloworldaction">HelloWorld.action</h3> |
| |
| <p>The mapping executes the HelloWorld action, contained in <code class="language-plaintext highlighter-rouge">src/main/java/tutorial/example/HelloWorld.action</code>. This action retrieves a message from a package-level properties file, contained in <code class="language-plaintext highlighter-rouge">src/main/resources/tutorial/package.properties</code>. See the <a href="/core-developers/localization">Localization page</a> for more information about how Struts 2 handles message resources (it’s pretty cool).</p> |
| |
| <h3 id="loginaction">Login.action</h3> |
| |
| <p>This is another wildcard mapping:</p> |
| |
| <div class="language-xml highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="nt"><action</span> <span class="na">name=</span><span class="s">"Login_*"</span> <span class="na">method=</span><span class="s">"{1}"</span> <span class="na">class=</span><span class="s">"tutorial2.example.Login"</span><span class="nt">></span> |
| <span class="nt"><result</span> <span class="na">name=</span><span class="s">"input"</span><span class="nt">></span>/example/Login.jsp<span class="nt"></result></span> |
| <span class="nt"><result</span> <span class="na">type=</span><span class="s">"redirectAction"</span><span class="nt">></span>Menu<span class="nt"></result></span> |
| <span class="nt"></action></span> |
| </code></pre></div></div> |
| |
| <p>In the application the Login action is reached via a link, but not directly to <code class="language-plaintext highlighter-rouge">/tutorial/example/Login.action</code>. The link is actually <code class="language-plaintext highlighter-rouge">/tutorial/example/Login_input.action</code>. Reaching the Login action this way bypasses validation: if we hit the Login action directly we’ll get a validation error.</p> |
| |
| <p>The validation configuration is contained in <code class="language-plaintext highlighter-rouge">/src/main/resources/tutorial/example/Login-validation.xml</code>. It checks for the presence of the <code class="language-plaintext highlighter-rouge">username</code> and <code class="language-plaintext highlighter-rouge">password</code> properties (form values). It uses messages stored in the <code class="language-plaintext highlighter-rouge">package.properties</code> file (in the same directory). See the <a href="/core-developers/validation">Validation page</a> for more information regarding Struts 2 validation.</p> |
| |
| </section> |
| </article> |
| |
| |
| <footer class="container"> |
| <div class="col-md-12"> |
| Copyright © 2000-2022 <a href="https://www.apache.org/">The Apache Software Foundation</a>. |
| Apache Struts, Struts, Apache, the Apache feather logo, and the Apache Struts project logos are |
| trademarks of The Apache Software Foundation. All Rights Reserved. |
| </div> |
| <div class="col-md-12">Logo and website design donated by <a href="https://softwaremill.com/">SoftwareMill</a>.</div> |
| </footer> |
| |
| <script>!function (d, s, id) { |
| var js, fjs = d.getElementsByTagName(s)[0]; |
| if (!d.getElementById(id)) { |
| js = d.createElement(s); |
| js.id = id; |
| js.src = "//platform.twitter.com/widgets.js"; |
| fjs.parentNode.insertBefore(js, fjs); |
| } |
| }(document, "script", "twitter-wjs");</script> |
| <script src="https://apis.google.com/js/platform.js" async="async" defer="defer"></script> |
| |
| <div id="fb-root"></div> |
| |
| <script>(function (d, s, id) { |
| var js, fjs = d.getElementsByTagName(s)[0]; |
| if (d.getElementById(id)) return; |
| js = d.createElement(s); |
| js.id = id; |
| js.src = "//connect.facebook.net/en_GB/all.js#xfbml=1"; |
| fjs.parentNode.insertBefore(js, fjs); |
| }(document, 'script', 'facebook-jssdk'));</script> |
| |
| |
| </body> |
| </html> |