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