struts1总结
来源:互联网 发布:云漫数据流量可以用吗 编辑:程序博客网 时间:2024/05/16 11:17
今天又重新看了一下徐老师讲的struts1,对struts1做了一下总结,感觉今天收获不少,以前总是安着老师写的流程走的,但是不知道是为什么有那样的流向,今天重新听了视频,又看了底层的代码,总算清楚了struts1的流程.
struts1:工作流程:JSP页面发出请求,ActionServlet进行处理,并找到struts-config.xml,并找到相应的Action映射(这个是通过path找到的,),通过Action映射找到actionFormbean,parameter="method"通个这个属性调用此action对应的方法,
执行了path,name之后执行scope="request|session",开始调用
判断request|session.getAttribute("userForm")==null是否为NULL,如果为NULL,则new UserForm();request|session.setAttribute("userForm",uf);然后把JSP页面上的信息封装到formbean里面,
validate="true"如果有这个属性的话,那么调用在actionFormBean里面的ActionErrors validate()方法;actionErrors返回到ActionServlet,在页面上显示的错误信息是request范围里面的,在request里进行ERROR的注入工作也是ActionServlet处理的,出错了就到input页面,如果没有错误就到type,这里面是具体的action;到了这一步也就到了Action中的方法;
在struts1中的中央处理器ActionServlet都做了那些工作?
(1).action的寻找
(2).formbean的寻找
(3).formbean的初始化
(4).页面的组装,
(5).把错误信息保存到request里面,
(6).参数传递问题,
(7).跳转问题,
(8).异常处理问题;
(9).国际化问题;这些工作都是actionServlet做的;
在struts1里面JSP与formbean是邦定的,所以在JSP显示的都与Formbean里面的属性的值对应;在action里面把V(view)----P(persistence),P()---->V转换这里面的就是FormBean视图层对像,,service层是userService.save(User).基于servlet. url-pattern 中央处理器: ActionServlet *.do /do/* 以.do结尾的,以/do/开头的请求都有中央处理器进行处理;缺点的. ActionForm(封装请求数据,
struts1提倡绑定技术,在web开发中最困难的就是表单的回显,一开始用JSP+JAVABEAN的话(EL表达式,还getProperty,),struts1为了不让在页面上处理JAVA代码,
struts1给出了标签库struts-html.tld(回显,<html:text property="age"/>),) tag
struts-html.tld(回显,<html:text property ="age" />)
domain/entity/persistence:Person(PersonForm) Customer Order,每一个实体类对应一个actionFormBean,在大的公司可能一个项目中就有几百个实体类,一个实体类对应一个ActionFormBean那就是几百个ActionFormBean,这样就会引起类的爆炸;
在web.xml文件中配置ActionServlet.
<servlet>..
<servlet-mapping> *.do
MVC:
Model
View
Controller:ActionServlet Action(业务控制器)
//HttpServletRequest req, HttpServletResponse res,这两个是属于servlet api 也就是javaee规范的一部分.所以struts1没有很好的实现解耦,什么是解耦?解耦就是尽量不让两个类靠在一起,因为action里面执行方法里面引用了servlet api
RegAction extends Action{
public ActionForward execute(ActionMapping am,
ActionForm af,
HttpServletRequest req,
HttpServletResponse res){
res.getWrite().println("<html >...");
}
}
WEB-INF/struts-config.xml
<struts-config>
<form-beans>
<form-bean name="userForm" type="....UserForm" />
</form-beans>
<actionmappings>
<action path="/regAction"
name="userForm"
scope="request|session"
validate="true"有了这一句就执行FormBean里面的validate()方法
input="/xxx.jsp"表单出错时要跳转的页面。
type="...RegAction">
<forward name="success" path="/" />它是全局的还是局部的
</actionmapping>
</struts-config>
singleton:单例,某个类在整个程序运行期间只有一个实例就是一单例;
prototype:原型.在struts中action是线程本地化的.
常规的web开发中,涉及到的公共任务有:
1.参数传递问题.
2.类型转换问题.
3.文件上传问题
4.国际化问题.
5.令牌重复提交问题.
6.异常处理问题.
DispathAction{
public ActionForward insertUser(....4){
}
public ActionForward insertUser(....4){
}
}
<action path=""
name
scope
validate
input="/error.jsp"
type
parameter="method">
url:http://.../userAction.do?method=insertUser
UserForm extends ActionForm{
public ActionErrors validate(){
return errors;
}
}
- struts1总结
- struts1 总结
- struts1总结
- struts1总结
- struts1总结
- struts1总结
- Struts1总结
- struts1总结
- Struts1配置文件总结
- struts1的总结
- struts1一点小总结
- struts1学习总结
- Struts1配置文件总结
- Struts1配置文件总结
- Spring整合Struts1总结
- Struts1 面试题目总结
- struts1.3总结
- struts1 知识总结
- 我对线程的一点新的认识
- usb-skeleton.c 之 03--那些个头头文文件件们
- Excel使用VBA动态设置打印区域
- connect to db2 with db2 client
- 唐骏:网游业的机遇与挑战
- struts1总结
- 一杯苦酒,一片落叶
- asm--换行符-回车符
- VC++ 多文档用户界面设计
- 诺基亚智能手机未来仅采用Symbian和MeeGo系统
- 当前各大企业云计算的发展形式之Google
- POJ 1459 Power Network
- Cocoa 框架概述
- 角色设计实例。(我的淘宝招聘答卷)(转帖)