1.使用步骤

1) 导入struts2的支持jar包

名称 说明
struts2-core-2.3.4.1.jar Structs2的核心类库
xwork-core-2.3.4.1.jar xwork的核心类库,webwork框架的支持,struts2的前身就是webwork
ognl-3.0.5.jar OGNL表达式语言类库
freemarker-2.3.19.jar Freemarker模板语言支持类库,视图技术
commons-beanutils-1.8.0.jar 封装javabean的工具类库
commons-fileupload-1.2.2.jar 文件上传支持类库
commons-io-2.0.1.jar 处理IO操作的工具类库
commons-lang3-3.1.jar 包含了一些数据类型工具类,是java.lang.*的扩展
javassist-3.11.0.GA.jar (JAVA编程助手)使Java字节码操纵简单。一个编辑Java字节码的类库

2) web.xml配置启动的全局的过滤器(Filter)。和ActionServlet类似。。。

  <!-- 配置启动struts2的全局过滤器 -->
<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>

3)编写不同的业务Action类 实现Action类,编写不同的业务方法,默认execute()方法

/**
* 登录逻辑的Action
* @author Administrator
*
*/
public class LoginAction implements Action {
// 默认调用方法
@Override
public String execute() throws Exception {
System.out.println("执行了LoginAction的execute方法");
// 返回标记
return "success";
}
}

4)在src目录下(类路径的根目录下),新建一个struts.xml,配置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="xxx" extends="struts-default">
<!-- 配置Action http://localhost:8080/day28_struts/login.action -->
<action name="login" class="com.chromer.action.LoginAction">
<result name="success" type="redirect">/index.jsp</result>
</action>
</package>
</struts>

5)访问Action的业务方法

http://localhost:8080/day28_struts/login.action

最新文章

  1. 【bzoj1486】 HNOI2009—最小圈
  2. 【HTML5 2】《html5 开发精要与实例讲解》 step1 -- 导读
  3. Sina App Engine(SAE)入门教程(7)- Storage使用
  4. 【CSS】Intermediate1:Class and ID Selectors
  5. [Audio processing] wav音频文件读取int和double数组的关系
  6. Ubuntu 14.04 上使用 Nginx 部署 Laravel
  7. ReSharper C++计划上市
  8. 移动端-H5预加载页面
  9. [基础架构]PeopleSoft工作原理(从浏览器发送请求开始)
  10. Understanding the Objective-C Runtime
  11. asp.net core系列 44 Web应用 布局
  12. 2018-2019-2 20165234 《网络对抗技术》 Exp0 Kali安装 Week1
  13. 将vcf文件转化为plink格式并且保持phasing状态
  14. Ionic3.x设置启动页与图标
  15. 题解——Codeforces Round #508 (Div. 2) T2 (构造)
  16. awk 中 fieldwidths使用方法
  17. python后端工程师 数据爬虫
  18. windows7安装svn客户端
  19. System V 共享内存 和 系列函数
  20. 201621123005《java程序设计》第五周学习总结

热门文章

  1. OLAP和数据挖掘的区别
  2. 多设备同时安装apk(安卓)
  3. 《O2O实战:二维码全渠道营销》读书笔记思维导图(530KB)
  4. 根据ip确定城市
  5. 八、IntelliJ IDEA 缓存和索引的介绍及清理方法
  6. 【题解】洛谷P2532 [AHOI2012]树屋阶梯(卡特兰数+高精)
  7. 【题解】POJ1845 Sumdiv(乘法逆元+约数和)
  8. Hive中使用LZO
  9. MYSQL添加外键关联
  10. 第一次接触mysql