一 使用声明的方式来处理Action中的错误流
1.在Action中仅关注正确的处理流程,所以得错误流程全部由配置的方式来完成
2 在Action中只考虑a取数据 b调业务 c转移
当业务失败抛出异常给主控制,主控制器在struts-config。xml中寻找行动方案中的处理方式
<exception type="异常类型名" key="资源文件的key" path="转移到报错页面"/>
3 在报错页面中加<html:error/>
二 struts标签
......
用标签实现上传
1 表单<html:form action="**.do" method="post" enctype="multipart/form-data">
<html:file property="属性名"></html:file>//属性名与行动方案中对应的类是org.apache.struts.upload.FormFile
<html:submit value="上传"/>
</html:form>
2 Action中 formFile提供重要方法a getFileName() b:getInputStream()
3 文件上传的本质即文件的复制
public ActionForward upload(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response)
throws FileNotFoundException, IOException {
DynaActionForm uploadForm = (DynaActionForm) form;
FormFile file=(FormFile)uploadForm.get("uploadFile");
String fileName=file.getFileName();
fileName=request.getRealPath("/upload")+"/"+fileName;
byte[] buffer=new byte[100*1024];
int length=-1;
InputStream in=file.getInputStream();
FileOutputStream out=new FileOutputStream(fileName);
while((length=in.read(buffer))!=-1)
{
out.write(buffer, 0, length);
}
in.close();
out.close();
return null;
}
三 j2ee的分层体系结构
1.J2ee分为3个逻辑层web,biz,dao代码依赖关系从上层到下层。当下层组件变动时上层也变动
2 通过门面接口加工厂形式来降低波动的出现。
所有跨层的访问基于接口来进行。
对于接口的实现由工厂来定位
Properties p = new properties()//集合类用于读取配置文件
InputStream in = Factory.class.getResourceAsStream("/biz.property");///从Classpath出发去寻找指定文件
p.load(in);//加载配置文件
String className = p.getProperty("biz.className");//取配置文件中的值
return (IBiz) Class.forName(className).newInstance();//反射生成实例
接口是什么
1 接口是用于封装变化的绝缘体,避免下层组件的波动影响到上层
2 接口是一个客户视图,将子系统中可以由客户进行的操作进行集中提供了入口
3 接口是一个契约,客户按照接口来调用子系统,子系统按照接口来实现。
接口扩充容易,消减难
抽象类是什么
1.抽象类是用于表述继承树的起点,抽象的方法表示由子类去实现,而非抽象的方法表示默认实现
2 体现了自顶向下,逐渐细化分解问题的设计思想。