asm-3.3.jar
asm-commons-3.3.jar
asm-tree-3.3.jar
commons-fileupload-1.2.2.jar
commons-io-2.0.1.jar
commons-lang3-3.1.jar
freemarker-2.3.19.jar
javassist-3.11.0.GA.jar
ognl-3.0.6.jar
struts2-core-2.3.8.jar
xwork-core-2.3.8.jar
2. 在web.xml中注册Struts2.3.8核心控制器
<?xml version="1.0" encoding="UTF-8"?> <web-app version="3.0" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"> <display-name>Struts2.3.8</display-name> <filter> <filter-name>struts2</filter-name> <filter-class>org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter</filter-class> </filter> <filter-mapping> <filter-name>struts2</filter-name> <url-pattern>/*</url-pattern> </filter-mapping> <welcome-file-list> <welcome-file>index.jsp</welcome-file> </welcome-file-list> </web-app>
3. 建立视图文件
chapter02/part01/input.jsp
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%> <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> <title>Chapter02 | Part01</title> </head> <body> <form id="helloForm" action="hello.action" method="post"> <table> <tr> <td>Your Name:</td> <td><input type="text" name="username"></td> </tr> <tr> <td> </td> <td><input type="submit" value="Submit"></td> </tr> </table> </form> </body> </html>
chapter02/part01/view.jsp
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%> <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> <title>Chapter02 | Part01</title> </head> <body> Hello! ${requestScope.username}! Welcome to Struts2.3.8 ... </body> </html>
4. 建立处理请求的Action
package chapter02.part01.action; public class HelloAction { private String username; public String execute() throws Exception { System.out.println("Hello! " + username + "! Welcome to Struts2.3.8 ..."); return "success"; } public String getUsername() { return username; } public void setUsername(String username) { this.username = username; } }
5. 在struts.xml中注册Struts2.3.8的Action
<?xml version="1.0" encoding="UTF-8" ?> <!DOCTYPE struts PUBLIC "-//Apache Software Foundation//DTD Struts Configuration 2.3//EN" "http://struts.apache.org/dtds/struts-2.3.dtd"> <struts> <package name="chapter02.part01" extends="struts-default"> <action name="hello" class="chapter02.part01.action.HelloAction"> <result>view.jsp</result> </action> </package> </struts>
6. 查看项目目录结构
7. 发布运行