springmvc+springioc/aop+jdbc
springmvc+springioc/aop+mybatis
struts2+springioc/aop+hibernate
1.Struts2
#简介
Apache
Struts1-->结束
WebWork2-->xwork内核-->Struts2
属于MVC框架,等价于springmvc
#Struts2的体系结构(MVC)
#Struts2的处理流程
-浏览器发请求,请求进入Filter主控制器
(struts.xml)
-Filter根据配置调用Action处理
-Action处理完毕返回结果(调Service/DAO)
-Filter调用Result生成响应结果
-响应结果输出
流程设计:
/hello.action
-->Filter(struts.xml)
-->HelloAction.execute
-->Result(dispatcher)
-->hello.jsp
#Struts2开发步骤
##搭建Struts2开发环境
-导入struts2开发包
-添加struts2配置文件src/struts.xml
##设计实现流程
##实现流程
ActionMapping
<action name="请求名" class="Action类">
</action>
#进入登陆页面
/user/tologin.do
-->Filter(struts.xml)
-->默认Action组件
-->Result(dispatcher)
-->/WEB-INF/login.jsp
public class Action{
public String execute(){
return "success";
}
}
#登录按钮处理
/user/login.do(username=xx;password=xxx)
-->Filter(struts.xml)
-->LoginAction.execute
-->Result(dispatcher)
-->成功:ok.jsp;失败:login.jsp
#Action编写规则
-Action配置规则<action>
-Action属性
既可以接收参数;又可以向外传值
接收:属性名和请求参数key保持一致
传值:属性名与JSP取值${key}保持一致
-Action方法:public String xxx(){}
默认方法名execute
-Action获取Request,Session对象
使用ActionContext API获取(Map结构)
使用ServletActionContext API 获取(原类型)
使用Aware系列接口(仅使用Action)
RequestAware,SessionAware,
ApplicationAware
ServletRequestAware,
ServletResponseAware,
ServletContextAware
public class SessionMap
extends AbstractMap{
private HttpSession session;
public SessionMap(HttpServletRequest request){
session = request.getSession();
}
public void put(Object key,Object value){
session.setAttribute(key,value);
}
public void get(Object key){
return session.getAttribute(key);
}
}
#综合练习
Struts2+MyBatis
/note/list.do
-->Filter(struts.xml)
-->NoteListAction.execute
-->NoteDao.findAll
-->Result(dispatcher)
-->note_list.jsp