[For super beginners] Struts2 Super Primer --2018 Edition

Introduction

Some may call it Legacy, but this is an introductory article on Struts 2. Recently, new client-side technologies have evolved, and some people may say that the server-side technology itself is legacy, let alone Struts2.

However, when you run into something that is currently in operation, you really need to understand it. I recently encountered such a pattern and studied hard.

When I tried to make HelloWorld, I had a hard time finding a document that covered everything, so I will write this article as a reminder of that time.

Struts2, even if it is said to be a legacy, seems to have a lot of version upgrades, and it is still new. At the time of writing this article, I would like to introduce through Hello World what you can build a development environment for Struts2 using the latest version.

1. What is Struts?

It is a web application framework that adopts the MVC model implemented in Java. The MVC model is the idea of separately implementing Model (data), View (screen), and Controller (business logic). However, although Struts2 has a function to separate V and C, it does not provide a function to separate M from C, so it is often realized by introducing an OR mapper etc. separately.

1.1. Background of Struts2

There used to be a framework called Struts that dominated the world, but Struts 2 is fundamentally different. The original development process is completely different, it seems that it was developed under the name "WebWork2", and that name was changed to Struts2 with the end of support for Struts.

Struts2 is still supported and new versions are released fairly often.

1.2. Benefits of introducing Struts2

It's a little off topic, but you can dramatically improve your productivity by deploying Struts2 in large-scale web applications such as enterprise systems. In addition, although it is not limited to Struts2, by introducing a framework, it is possible to absorb and level the differences in implementation policies due to the habits of developers. However, the author thinks that it is not suitable for small-scale development because it takes time to introduce.

2. Development environment construction

From now on, we will build a development environment to realize Hello World with Struts2. There are three ways to build it.

  1. Build by yourself
  2. Built with Maven
  3. Use the official empty project

This time, I will build it by myself.

2 is that you need to study Maven first, and it may not be available depending on the environment. Even if you try to use 3, you cannot start it from the default state with an error, so it is faster to build it by yourself than to use it.

Therefore, let's build it by ourselves, also by moving our hands and remembering it!

2.1. Creating an Eclipse project

The author uses an integrated development environment for basic development. I think that basic Eclipse will be used for Java development, but this time I will use Eclipse as well.

The environment I am using is "Eclipse 4.4 (Luna)". The versions of Eclipse can be different, so readers should use the one that is close to them.

① Select File > New > Other > Web > Dynamic Web Project and proceed to the next. p1.jpg

② Enter the following information to proceed to the next.

Setting items Set value
Project name Struts2HelloWorld
※Project nameは自由に決めていただいて構いません
Target runtime Tomcat8 (Java8)
Dynamic web module version 3.1
Constitution Tomcat8 (Java8)デフォルトConstitution

p2.jpg

③ Add the "resources" folder by adding a folder and proceed to the next. p3.jpg

(4) Check the generation of web.xml deployment descriptor and complete. p4.jpg

⑤ If the project is completed as shown in the image below, the project creation is complete. p5.JPG

2.2. Introduction of Struts2

Introduce Struts2 to the created project.

2.2.1. Download Struts2

Download Struts 2 from here. At the time of writing this article, the latest version seems to be "2.5.14.1". Although not used in HelloWorld, download "struts-2.5.14.1-all.zip" with a sample application. Also, please download "log4j-core-2.9.1.jar" separately as you will need it later. Please match the version of the jar file downloaded here with log4j-api. p6.jpg

"Struts-2.5.14.1-min-lib.zip" is an empty Struts2 project with a minimum configuration. In my environment, I couldn't start with an error from the beginning. It was a hassle to solve, so I built it myself from the beginning, but I would appreciate it if you could comment if you were able to use it well.

2.2.2. Placement of required libraries

Introduce Struts 2 to your project. Unzip the downloaded struts-2.5.14.1-all.zip and copy the following jar file from the lib folder to the "project root / Struts2HelloWorld / WebContent / WEB-INF / lib" folder.

file name Remarks
commons-fileupload-1.3.3.jar
commons-io-2.5.jar
commons-lang-2.4.jar
commons-lang3-3.6.jar
commons-logging-1.1.3.jar
freemarker-2.3.26-incubating.jar
javassist-3.20.0-GA.jar
log4j-api-2.9.1.jar
log4j-core-2.9.1.jar This is a separately downloaded jar file.
log4j-Please match the version with api.
ognl-3.1.15.jar
struts2-core-2.5.14.1.jar
xmlpull-1.1.3.1.jar
xpp3_min-1.1.4c.jar
xstream-1.4.10.jar

This is the minimum library configuration for running Struts2. p7.JPG

2.2.3. Arrangement of configuration files

Create "struts.xml" which is the configuration file of Struts2 in "/ Struts2 HelloWorld / resources".

As an aside, Struts2 allows you to implement your application without an XML configuration file, which is called zero configuration. However, do developers like XML? Even if Struts2 is introduced, most of the cases I have seen are written in XML. Although there is an advantage that the application settings can be understood only by looking at this file, the author thinks that there is nothing better than not, considering the trouble of writing the setting file.

Especially in Struts2, as mentioned at the beginning, it is often used in combination with other frameworks such as Spring and OR mapper, and each framework requires an XML configuration file, so the amount of XML to be managed increases tremendously. It should be a zero configuration to free the developer from that XML hell, but for some reason it is not used (laugh)

It's been a long time, but this time I will write the configuration file together for more cases. I've included comments along with it, but skip it for now.

■ Contents of struts.xml <!-Action package definition-> <!-Hello world sample action-> /view/sample/HelloWorld.jsp

Another, place the setting file "log4j2.xml" of "log4j2" which is a log output library.

■ Contents of log4j2.xml (Please restore the comment part arbitrarily) <!-Appender settings used for logging-> [%d{yyyy-MM-dd HH:mm:ss.SSS}], %-5p, %t, %c, %m%n

<!-Logger settings used for output->

This is not necessary, but it is convenient to place a file called "struts.properties" in the same folder and write "struts.ui.theme = simple" because it can suppress the automatic style sheet tag generation by Struts2.

2.3 Confirmation of configuration

At this point, the introduction of Struts 2 is complete. I've done a fair amount of work, so I'll list the tree of the projects I've configured. If the project has the following tree, the development environment construction is complete.

■ Project tree structure Application root ├─src ├─resources │ log4j2.xml │ struts.properties │ struts.xml │ ├─build │ └─classes * The same materials placed in the source folder are automatically generated here. │ log4j2.xml │ struts.properties │ struts.xml └─WebContent ├─META-INF │ MANIFEST.MF │ └─WEB-INF │ web.xml │ └─lib commons-fileupload-1.3.3.jar commons-io-2.5.jar commons-lang-2.4.jar commons-lang3-3.6.jar commons-logging-1.1.3.jar freemarker-2.3.26-incubating.jar javassist-3.20.0-GA.jar log4j-api-2.9.1.jar log4j-core-2.9.1.jar ognl-3.1.15.jar struts2-core-2.5.14.1.jar xmlpull-1.1.3.1.jar xpp3_min-1.1.4c.jar xstream-1.4.10.jar

3. Application implementation

Now that we have built the development environment, we will start implementing the application itself.

3.1. Preparation of top page

Prepare the top page when accessing the application. This time, we will implement it using JSP.

Right-click WebContent> New> JSP to open the dialog. Enter "index.jsp" in the file name to complete. p8.jpg

■index.jsp
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>

<!-Enable Struts2 tag library-> <%@ taglib prefix="s" uri="/struts-tags"%> <!-Use HTML5-type declarations->

Hello World in Struts2 </ title> </head> <body> <!-Input form uses Struts2 tags-> <s:form action="hello"> <s:textfield name="name" /> <s: submit value = "Go to Hello World page" /> </s:form> </body> </html> <h2>3.2. Implementation of Action</h2> <p>In Struts2, the class responsible for processing Web applications, such as when submitted by JSP, is called Action. Action and transition destination page are defined in struts.xml, but I will explain it later, so please implement as follows at the moment.</p> <p>Right-click on the src folder> New> From Class, enter the following information to complete.</p> <table> <thead> <tr> <th style="text-align:left">Input items</th> <th style="text-align:left">Input value</th> </tr> </thead> <tbody> <tr> <td style="text-align:left">package</td> <td style="text-align:left">sample</td> </tr> <tr> <td style="text-align:left">name</td> <td style="text-align:left">HelloWorldAction</td> </tr> </tbody> </table> <p><img src="https://qiita-image-store.s3.amazonaws.com/0/189344/cd06f569-89c9-dd9a-5a00-eb14c7ee6b87.jpeg" alt="p9.jpg" /></p> <pre><code>■HelloWorldAction package sample; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; /** </code></pre> <ul> <li>[Hello World Action Class] <br> <ul> <li> <br> </li> <li>@author tarosa0001 */ public class HelloWorldAction { / ** Logger * / private Logger logger = LogManager.getLogger(HelloWorldAction.class);</li> </ul> </li> </ul> <p>/** name */ private String name;</p> <pre><code> /** </code></pre> <ul> <li> <p>[Action execution process] <br></p> </li> <li> <p>Execute the process to output Hello World. <br></p> </li> <li> <p>Implement the method to be executed using the method name specified in struts.xml. <br></p> </li> <li> <p>In Struts2, the page transition destination is determined by the processing result of the action,</p> </li> <li> <p>This time, the fixed character string of "success" is returned. <br> * <br> * @return */ public String execute() { logger.info ("The parameter entered is" {} ".", name); return "success"; }</p> <pre><code> /** </code></pre> </li> <li> <p>[Name acquisition process] <br></p> </li> <li> <p>Get the name. <br></p> </li> <li> <p>When Struts2 takes the value entered in the form as a parameter</p> </li> <li> <p>Because getter is used, the information you want to use as a parameter is</p> </li> <li> <p>Declare it as a property of Action class and prepare a getter. * <br></p> </li> <li> <p>@return name */ public String getName() { return name; }</p> <pre><code> /** </code></pre> </li> <li> <p>[Name setting process] <br></p> </li> <li> <p>Set the name. <br></p> </li> <li> <p>As with getters, prepare setters for the values you want to pass between pages. <br> * <br></p> </li> <li> <p>@param name name */ public void setName(String name) { this.name = name; } }</p> </li> </ul> <h2>3.3. Implementation of transition destination</h2> <p>Implement the transition destination when the button on the top page is pressed. Create a view / sample folder in the WebContent directory and place the transition destination page there. The location directory itself can be anywhere in WebContent, but this time it will be the above directory. Add "HelloWorld.jsp" to the sample folder in the same procedure as the top page.</p> <pre><code>■HelloWorld.jsp <%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%> <%@ taglib prefix="s" uri="/struts-tags"%> <!DOCTYPE html> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> <title>Hello Struts2 world!</title> </head> <body> </code></pre> <p><!-Displays the data passed between messages. -> Hello Struts2 world, <s: property value = "name" /> </body> </html></p> <h2>3.4. Update application settings</h2> <p>At this point, the application processing itself has been implemented. Finally, configure the implemented application to operate as a Struts2 application.</p> <p>Please change "web.xml" existing in the WEB-INF of the project as follows. Since it is a basic knowledge of the web application itself rather than Struts2, the explanation of web.xml itself is omitted.</p> <pre><code>■web.xml <?xml version="1.0" encoding="UTF-8"?> <web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://xmlns.jcp.org/xml/ns/javaee" xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd" id="WebApp_ID" version="3.1"> <display-name>Struts2HelloWorld</display-name> <welcome-file-list> </code></pre> <p><!-Display file settings when the application root is addicted-> <!-It is not necessary, but this time we will only use index.jsp to prevent typos in the URL. -> <welcome-file>index.jsp</welcome-file> </welcome-file-list></p> <p><!-Struts2 Servlet Filter-> <filter> <filter-name>struts2</filter-name> <filter-class>org.apache.struts2.dispatcher.filter.StrutsPrepareAndExecuteFilter</filter-class> </filter></p> <p><!-Filter settings to use for URLs-> <filter-mapping> <filter-name>struts2</filter-name> <url-pattern>/*</url-pattern> </filter-mapping> </web-app></p> <h2>3.5. Implementation completed</h2> <p>The web.xml settings have also been updated, and the implementation of the Struts2 application is finally complete. For confirmation, I will list the final tree.</p> <p>■ Completed project tree Project root ├─src │ └─sample │ HelloWorldAction.java │ ├─resources │ log4j2.xml │ struts.properties │ struts.xml │ ├─build │ └─classes │ │ log4j2.xml │ │ struts.properties │ │ struts.xml │ │ │ └─sample │ HelloWorldAction.class │ └─WebContent │ index.jsp │ ├─META-INF │ MANIFEST.MF │ ├─view │ └─sample │ HelloWorld.jsp │ └─WEB-INF │ web.xml │ └─lib commons-fileupload-1.3.3.jar commons-io-2.5.jar commons-lang-2.4.jar commons-lang3-3.6.jar commons-logging-1.1.3.jar freemarker-2.3.26-incubating.jar javassist-3.20.0-GA.jar log4j-api-2.9.1.jar log4j-core-2.9.1.jar ognl-3.1.15.jar struts2-core-2.5.14.1.jar xmlpull-1.1.3.1.jar xpp3_min-1.1.4c.jar xstream-1.4.10.jar</p> <h1>4. Run</h1> <p>By now, the implementation and configuration are complete. Finally, run the implemented application.</p> <h2>4.1. Tomcat preparation</h2> <p>Prepare a Servlet container to run the web application. This time we will use Tomcat as the Servlet container.</p> <p>(1) Select Window> View View> Others> Server to display the server view. <img src="https://qiita-image-store.s3.amazonaws.com/0/189344/85194334-17c2-42d8-a948-07046747306c.jpeg" alt="p10.jpg" /></p> <p>(2) Right-click the displayed server view margin> New> Select Server to display the new server dialog. Select "Tomcat v8.0 Server" and proceed to the next. <img src="https://qiita-image-store.s3.amazonaws.com/0/189344/7f9d0c59-9921-fd44-c2d9-fdfdfcad098a.jpeg" alt="p11.jpg" /></p> <p>③ Add Struts2HelloWorld and complete <img src="https://qiita-image-store.s3.amazonaws.com/0/189344/b67d289a-c698-6e15-1b33-3db62a2c38a7.jpeg" alt="p12.jpg" /></p> <ul> <li>If Struts2HelloWorld cannot be added, it is possible that the project creation has failed. Make sure your project configuration is compatible with Tomcat 8.</li> </ul> <h2>4.2. Start Tomcat</h2> <p>Start Tomcat. Right-click on Tomcat added to the server view and start. <img src="https://qiita-image-store.s3.amazonaws.com/0/189344/003f2b34-3ebc-ee0c-f078-b5cf92b3ea27.jpeg" alt="p13.jpg" /></p> <p>The following character string is output to the console. It appears in red, but it is not an error.</p> <p>■ Console output * Ignore the warning. Warning: [SetPropertiesRule] {Server / Service / Engine / Host / Context} Setting property'source' to'org.eclipse.jst.jee.server: Struts2HelloWorld' did not find a matching property. [Tue 2 13 00:39: 25 JST 2018] Info: Server version: Apache Tomcat / 8.0.20 [Tue 2 13 00:39:25 JST 2018] Info: Server built: Feb 15 2015 18:10:42 UTC [Tue 2 13 00:39:25 JST 2018] Info: Server number: 8.0.20.0 [Tue 2 13 00:39:25 JST 2018] Info: OS Name: Windows 7 [Tue 2 13 00:39:25 JST 2018] Info: OS Version: 6.1 [Tue 2 13 00:39:25 JST 2018] Info: Architecture: amd64 [Tue 2 13 00:39:25 JST 2018] Info: Java Home: C: \ Users \ Nakajima \ Desktop \ Personal \ Skill Up \ pleiades \ eclipse \ jre \ jre [Tue 2 13 00:39:25 JST 2018] Info: JVM Version: 1.8.0_40-b25 [Tue 2 13 00:39:25 JST 2018] Info: JVM Vendor: Oracle Corporation [Tue 2 13 00:39:25 JST 2018] Info: CATALINA_BASE: C: \ Users \ Nakajima \ Desktop \ Personal \ Skill Up \ pleiades \ sample \ .metadata \ .plugins \ org.eclipse.wst.server.core \ tmp0 [Tue 2 13 00:39:25 JST 2018 ] Info: CATALINA_HOME: C: \ Users \ Nakajima \ Desktop \ Personal \ Skill Up \ pleiades \ tomcat \ 8 [Tue 2 13 00:39:25 JST 2018] Info: Command line argument: -Dcatalina.base = C: \ Users \ Nakajima \ Desktop \ Personal \ Skill Up \ pleiades \ sample \ .metadata \ .plugins \ org.eclipse.wst.server.core \ tmp0 [Tue 2 13 00:39:25 JST 2018] Info: Command line argument: -Dcatalina.home = C: \ Users \ Nakajima \ Desktop \ Personal \ Skill Up \ pleiades \ tomcat \ 8 [Tue 2 13 00:39:26 JST 2018] Info: Command line argument: -Dwtp.deploy = C: \ Users \ Nakajima \ Desktop \ Personal \ Skill Up \ pleiades \ sample \ .metadata \ .plugins \ org.eclipse.wst.server.core \ tmp0 \ wtpwebapps [Tue] 2 13 00:39:26 JST 2018] Info: Command line argument: -Djava.endorsed.dirs = C: \ Users \ Nakajima \ Desktop \ Personal \ Skill Up \ pleiades \ tomcat \ 8 \ endorsed [Tue 2 13 00:39:26 JST 2018] Info: Command line argument: -Dfile.encoding = UTF-8 [Tue 2 13 00:39:26 JST 2018] Info: The APR based Apache Tomcat Native library which allows optimal performance in production environments was not found on the java.library.path: C: \ Users \ Nakajima \ Desktop \ Personal \ Skill Up \ pleiades \ eclipse \ jre \ bin; C : \ Windows \ Sun \ Java \ bin; C: \ Windows \ system32; C: \ Windows; C: / Users / Nakajima / Desktop / Personal / Skill up / pleiades / eclipse / jre / bin / ../ jre / bin / server; C: / Users / Nakajima / Desktop / Personal / Skill up / pleiades / eclipse / jre / bin / ../ jre / bin; C: / Users / Nakajima / Desktop / Personal / Skill up / pleiades / eclipse / jre / bin / ../ jre / lib / amd64; C: \ Users \ Nakajima \ Desktop \ Personal \ Skill up \ pleiades \ java \ 8 \ bin; C: \ gradle-4.0 \ bin; C: \ app \ Nakajima \ product \ 11.2.0 \ dbhome_1 \ bin; C: \ Windows \ system32; C: \ Windows; C: \ Windows \ System32 \ Wbem; C: \ Windows \ System32 \ WindowsPowerShell \ v1.0 ; C: \ Program Files \ WIDCOMM \ Bluetooth Software ; C: \ Program Files \ WIDCOMM \ Bluetooth Software \ syswow64; C: \ Program Files \ Intel \ WiFi \ bin ; C: \ Program Files \ Common Files \ Intel \ WirelessCommon ; C: \ Program Files (x86) \ Justsystems \ JSLIB32 ; C: \ Program Files (x86) \ Sony \ VAIO Startup Setting Tool; C: \ Program Files (x86) \ Common Files \ Sony Shared \ FeliCaLibrary; C: \ Program Files \ Common Files \ Sony Shared \ FeliCaLibrary; C: \ Program Files (x86) \ Common Files \ Sony Shared \ FeliCaNFCLibrary; C: \ Program Files \ Common Files \ Sony Shared \ FeliCaNFCLibrary; C: \ Program Files (x86) \ GtkSharp \ 2.12 \ bin; C: \ maven \ bin; C: \ Program Files \ nodejs \ v6.10.2 \ C: \ cygwin64 \ bin; C: \ Users \ Nakajima \ AppData \ Roaming \ npm; C: \ ProgramData \ Oracle \ Java \ javapath ;; C: \ Users \ Nakajima \ Desktop \ Personal \ Skill up \ pleiades \ eclipse ;;. [Tue 2 13 00:39:26 JST 2018] Info: Initializing ProtocolHandler ["http-nio-8080"] [Tue 2 13 00:39:26 JST 2018] Info: Using a shared selector for servlet write / read [Tue 2 13 00:39:26 JST 2018] Info: Initializing ProtocolHandler ["ajp-nio-8009"] [Tue 2 13 00:39:26 JST 2018] Info: Using a shared selector for servlet write / read [Tue 2 13 00:39:26 JST 2018] Info: Initialization processed in 951 ms [Tue 2 13 00:39:26 JST 2018] Info: Start service Catalina [Tuesday 2 13 00:39:26 JST 2018] Info: Starting Servlet Engine: Apache Tomcat / 8.0.20 [Tue 2 13 00:39:26 JST 2018] Info: Creation of SecureRandom instance for session ID generation using [SHA1PRNG] took [117] milliseconds. [Tue 2 13 00:39:26 JST 2018] Info: Starting ProtocolHandler ["http-nio-8080"] [Tue 2 13 00:39:30 JST 2018] Info: Starting ProtocolHandler ["ajp-nio-8009"] [Tue 2 13 00:39:30 JST 2018] Info: Server startup in 4438 ms [Tue 2 13 00:39:30 JST 2018]</p> <p>If "Server startup ~" appears, the startup is complete.</p> <h2>4.3. Access the application</h2> <p>Start your browser and enter the following URL to access the web application. 「http://localhost:8080/Struts2HelloWorld」</p> <p>Then, the contents of the implemented index.jsp will be displayed. <img src="https://qiita-image-store.s3.amazonaws.com/0/189344/9dffcdec-a57a-7aef-c743-92c8c0bdcf91.jpeg" alt="p14.jpg" /></p> <h2>4.4. Transition to Hello World page</h2> <p>Now, let's run Hello World, which we have implemented for a long time. Enter any value in the text box and click "Go to Hello World Page".</p> <p>Congratulations! The input value of the text box is inherited, and Hello World can be displayed! <img src="https://qiita-image-store.s3.amazonaws.com/0/189344/797045f0-f1c9-2c7b-69a0-1a7bf14f837f.jpeg" alt="p15.jpg" /></p> <p>Since the process to output the log to Action is implemented, the passed data can be confirmed by the log output to the console.</p> <h1>5. Application description</h1> <p>Thank you everyone. At this point, the Hello World implementation is complete. From here, we will explain the application.</p> <h2>5.1. JSPs and actions</h2> <p>Struts2 uses the MVC model. In many cases, View (screen) is implemented using JSP, and processing of each form and link of JSP is implemented by class using Java.</p> <p>5.1.1. Action Action is a class that performs business processing in Struts2. When submitting a JSP form, the Struts2 function calls Action. What action to perform on which form is defined in the form tag and Struts.xml.</p> <p>This time, the Action of HelloWorld is set here.</p> <p><!-Specify the Action to be executed in the action attribute of the form tag. -> <s:form action="hello"></p> <p>Struts2 provides a tag library that can be used in JSP, and when implementing an application using Struts2, most of them use the tag library provided by Struts2. The Action to be used when submitting the form is specified in the action attribute of the \ <s: form> tag, and the specific setting of the Action is described in Struts.xml. Struts.xml will be explained later, so I will explain it in detail there.</p> <h3>5.1.2. Data to be passed</h3> <p>Data used in the next screen and Action class, such as the form entered on the screen, is stored as a property in the Action class. If you set a property with a name that matches the name attribute set in the tag on the JSP, the value will be set in the property corresponding to the form by the Struts2 function.</p> <p>This time, only the name entered in index.jsp is passed, but the larger the page, the more data will be passed. In such a case, you may want to create a class that holds data as a chunk. In such a case, add ". (Dot)" to the name attribute and describe it in the format of "class name.property name".</p> <p>■ Example: When setting a value for name of the LoginInfo class <s:textfield name="LoginInfo.name" /></p> <p>5.2. Struts.xml Struts.xml is a configuration file that controls the behavior of Struts2. Here, the Action settings in the form tag explained earlier and the constants used in the application are defined. I've only touched on constants a bit, but you can also list them all together in struts.properties.</p> <p>There are various other settings, but here we will only explain the Action used in Hello World. In Struts.xml, Hello World Action settings are here.</p> <p>■ Hello World action setting location <!-Hello world sample action-> <action name="hello" class="sample.HelloWorldAction" method="execute"> <result name="success">/view/sample/HelloWorld.jsp</result> </action></p> <p>In Struts2, set the name of the Action, the class to use, and the method. In the defined Action, the next transition destination is defined by the return value from the Action class. This time, it is defined only when the return value is "success", but if you want to divide the transition destination according to the result of processing in Action, describe the \ <result> tag for each return value.</p> <p>The transition destination JSP describes the tree after WebContent as the root (/). You can also set the relative path from the transition source JSP, but it may shift, so it is better to describe it with the absolute path from the application root.</p> <p>5.3. web.xml web.xml is a file that describes the settings of the web application, but when using Struts2, it is necessary to define the servlet filter and mapping for Struts2. This does not change from the contents of web.xml mentioned above unless you do something special.</p> <h1>Finally</h1> <p>So far, the sample web application using Struts2 and the application description are all. This time it is just a sample, so I implemented it with the minimum configuration. It may not be easy to build a new Struts2 application from scratch, but there are many other features, so if you are interested, please give it a try.</p> <h1>EX. Reference Web</h1> <p>In writing this article, I referred to the web page posted below.</p> <p>・ Introduction to Java Web application development with 2014 version Eclipse + Struts2 http://www.cyokodog.net/blog/first-struts2/</p> <!-- ENDDDDDDDDDDDDDDDDDDDDDDDDDDDDD --> <script async src="https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js"></script> <!-- post_new_ui_horiz --> <ins class="adsbygoogle" style="display:block" data-ad-client="ca-pub-5469278205356604" data-ad-slot="4209814965" data-ad-format="auto" data-full-width-responsive="true"></ins> <script> (adsbygoogle = window.adsbygoogle || []).push({}); </script> <div style="margin-top: 30px;"> <div class="link-top" style="margin-top: 1px;"></div> <p> <font size="4">Recommended Posts</font> <!-- BEGIN LINK ************************* --> <div style="margin-top: 10px;"> <a href="/en/889faa2ab5853005f26b">[For super beginners] Struts2 Super Primer --2018 Edition</a> </div> <div style="margin-top: 10px;"> <a href="/en/70a1efa9edac2d83ba1a">[For super beginners] DBUnit super introduction</a> </div> <div style="margin-top: 10px;"> <a href="/en/93c19155bc803f10cea0">[For super beginners] Ant super introduction</a> </div> <div style="margin-top: 10px;"> <a href="/en/e5667cfa857529900216">[For super beginners] Maven super introduction</a> </div> <div style="margin-top: 10px;"> <a href="/en/8b500ff605fe9246bd28">[For super beginners] Mirage SQL super introduction</a> </div> <div style="margin-top: 10px;"> <a href="/en/80cb21319531ae2e02b9">[For super super beginners] What is object orientation?</a> </div> <div style="margin-top: 10px;"> <a href="/en/db3badd0810f39d97cba">[For super beginners] How to use autofocus: true</a> </div> <div style="margin-top: 10px;"> <a href="/en/f6d155f8c431033b37b2">How to use GitHub for super beginners (team development)</a> </div> <div style="margin-top: 10px;"> <a href="/en/ff652a932c451e3d21b9">Scraping for beginners (Ruby)</a> </div> <div style="margin-top: 10px;"> <a href="/en/3c43b674e2b7c4b5c5cb">Java debug execution [for Java beginners]</a> </div> <div style="margin-top: 10px;"> <a href="/en/8b1dfa2204dc3890f5f1">(For beginners) [Rails] Install Devise</a> </div> <div style="margin-top: 10px;"> <a href="/en/a0566982022983d0305e">More usable Enumerable for beginners</a> </div> <div style="margin-top: 10px;"> <a href="/en/b660bb9744e26b95a209">Java for beginners, data hiding</a> </div> <div style="margin-top: 10px;"> <a href="/en/ec79fc901e956ae90b30">Java application for beginners: stream</a> </div> <!-- END LINK ************************* --> </p> </div> </div> </div> <div class="footer text-center" style="margin-top: 40px;"> <!-- <p> Licensed under cc by-sa 3.0 with attribution required. </p> --> </div> <script src="https://cdn.jsdelivr.net/npm/jquery@3.4.1/dist/jquery.min.js"></script> <script src="https://cdn.jsdelivr.net/npm/bootstrap@4.3.1/dist/js/bootstrap.min.js"></script> <script src="https://cdn.jsdelivr.net/gh/highlightjs/cdn-release@10.1.2/build/highlight.min.js"></script> <script> $(document).ready(function() { var cfg_post_height = 60; var cfg_per = 0.51; var ads_obj = $('<ins class="adsbygoogle" style="display:block; text-align:center;" data-ad-layout="in-article" data-ad-format="fluid" data-ad-client="ca-pub-5469278205356604" data-ad-slot="7950405964"></ins>'); $('pre code').each(function(i, e) {hljs.highlightBlock(e)}); function getDocumentOffsetPosition( el ) { var _x = 0; var _y = 0; while( el && !isNaN( el.offsetLeft ) && !isNaN( el.offsetTop ) ) { _x += el.offsetLeft - el.scrollLeft; _y += el.offsetTop - el.scrollTop; el = el.offsetParent; } return { top: _y, left: _x }; } if ( $( "#article202011" ).length ) { var h1_pos = getDocumentOffsetPosition($('h1')[0]); var footer_pos = getDocumentOffsetPosition($('.link-top')[0]); var post_distance = footer_pos.top - h1_pos.top; // console.log('h1_pos: '+ h1_pos.top); // console.log(cfg_post_height) if((post_distance/h1_pos.top)>=cfg_post_height) { // console.log('tesssssssssssssssssssssssssssssssss'); $( ".container p" ).each(function( index ) { var p_tag_pos = $(this).position().top; var dis = p_tag_pos - h1_pos.top; var per = dis/post_distance; if(per>cfg_per) { ads_obj.insertAfter($(this)); (adsbygoogle = window.adsbygoogle || []).push({}); console.log( index + ": " + $( this ).text() ); return false; } }); } } }); </script> <script async src="//pagead2.googlesyndication.com/pagead/js/adsbygoogle.js"></script> <script> (adsbygoogle = window.adsbygoogle || []).push({}); </script> <!-- ads --> <script data-ad-client="ca-pub-5469278205356604" async src="https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js" type="d7540fe192d881abe59fcf57-text/javascript"></script> <!-- end ads --> </body> </html>