Java Reference
In-Depth Information
You can add the struts 2-core dependency to your pom.xml file, as illustrated in Listing 4-26.
Listing 4-26. struts 2-core Dependency
<dependency>
<groupId>org.apache.struts</groupId>
<artifactId>struts 2-core</artifactId>
<version>2.3.15.1</version>
<type>jar</type>
<scope>compile</scope>
</dependency>
You can use the same web.xml file used earlier in the HelloWorld project. Modify the welcome-file-list
file, as illustrated in Listing 4-27.
Listing 4-27. Welcome File
<welcome-file-list>
<welcome-file>login.jsp</welcome-file>
</welcome-file-list>
Listing 4-28 illustrates the login.jsp file.
Listing 4-28. login.jsp
1.<%@ page contentType="text/html; charset=UTF-8"%>
2.<%@ taglib prefix="s" uri="/struts-tags"%>
3.<html>
4.<head>
5.<title>Bookstore Login</title>
6.</head>
7.<body>
8.<h3>Login Bookstore</h3>
9.<s:actionerror />
10.<s:form action="login.action" method="post">
11.<s:textfield name="username" key="label.username" size="30" />
12.<s:password name="password" key="label.password" size="30" />
13.<s:submit method="execute" align="center" />
14.</s:form>
15.</body>
16.</html>
Listing 4-28 illustrates the usage of several Struts 2 tags. This is a login form that allows the user
to input a username and password. In line 10, the name of the action login is sent to the container
when the user submits the form. This action name is mapped to LoginAction via struts.xml ,
as illustrated in Listing 4-29.
 
Search WWH ::




Custom Search