上传
1.jsp 的form里添加enctype=“multipart/form-data”属性
2.action的处理
1)变量
private file a;
private String aFileName;//不用负值定义后直接用
private String aContentType;;//不用负值定义后直接用
2)上传文件流程
//定义一个输入流
FileInputStream in=new FileInputStream(a);
//定义上传路径
String uploadPath="c:/upload";//服务器的位置
//String 项目路径=HttpActionContext.getRequest().getRealPath("/upload");//服务器项目包下的路径(项目部署时就没啦)
//设置目标文件
File tofile=new File(uploadPath,aFileName);
//定义输出流
OutPutStream out=new FileOutPutStream(tofile);
//定义缓存
byte[] buffer =new byte[100];
int length=0;
//把a文件的输入流输出到tofile文件中
while((length=in.read(buffer))>0){
out.write(buffer,0,lenth);
}
//关闭输入流
in.close();
//关闭输出流
out.close();
3struts.xml 正常配置