- 写一个mystruts框架
MVC模式:
Model 模型
View 视图
Control 控制器
Control, 控制器
Servlet起到控制器作用!
—-》 获取请求数据封装 【BeanUtils可以优化,(调用方法?)】
—-》 调用Service处理业务逻辑
—-》 跳转(转发/重定向) 【跳转代码写死】
传统mvc开发总结:
1. 跳转代码写死,不灵活
2. 每次都去写servlet,web.xml中配置servlet!
(配置目的: 请求, Servlet处理类)
需求:
登陆、注册
登陆成功 – 首页
注册成功
– 登陆
– 首页
- 基于mvc模式的应用框架之struts
Struts就是基于mvc模式的框架!
(struts其实也是servlet封装,提高开发效率!)
Struts开发步骤:
1. web项目,引入struts - jar包
2. web.xml中,引入struts的核心功能
配置过滤器
3. 开发action
4. 配置action
src/struts.xml
- 引入8个jar文件
- web.xml
struts2
org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter
struts2
/*
开发Action
// 开发action: 处理请求
public class HelloAction extends ActionSupport {// 处理请求
public String execute() throws Exception {
System.out.println(“访问到了action,正在处理请求”);
System.out.println(“调用service”);
return “success”;
}
}配置action : src/struts.xml