Learn Java for Web Development

(Tina Meador) #1

186 CHAPTER 4: Building a Web Application Using Struts 2


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



org.apache.struts
struts 2-core
2.3.15.1
jar
compile

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



login.jsp

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.
4.
5.Bookstore Login
6.
7.
8.

Login Bookstore


9.
10.
11.
12.
13.
14.</s:form>
15.
16.


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.

Free download pdf