主要是关于文件上传和下载

<!-- 找到了~!隐藏表单域!! -->

<!-- 自动回显 -->

 

我先写一写需求

我现在仅仅完成了数据库的增和改

(还少了前端验证和图片,和回显和,算了 ,少了好多

1

要写图片上传

(地址就行先)

2

要写前端验证,回显

3

要修改图片(不想写。。。)

4

要写模糊查询(如果写完了写个分页查询)

5

删除

 

先就这些吧这些感觉就要写好久了

这次边写边总结

好了我要开始写图片了fightingfighting!

 

写图片是真的麻烦啊,

这次遇到的bug是

我用的Struts标签提交的,

他把名字自己封装成了user.getPic()

所以我再用之前的

private file pic

就接不到值了

需要重新建个file

File file = new File(user.getPic());

写的话是写以前的名字

 

 

再说一说老师的,突然磨磨蹭蹭不想说了

一会自己再想一遍

显示失败了,。。。

我来写一写下载吧

算了主要也就是这几个功能啊大兄弟

不写就没得写了

还是写文件吧

先搞清楚上传,再写下载

 

 

private File pic
private String picFileName
 
 
//上传
public String upload()
{
String path = ServletActionContext.getActionContext().getRealPath(“WEB-INF/upload”);
File dir = new File(path);
if(!dir.exists())
{
dir.mkdirs();
}
String child=getChileDirectory(dir);
user.setPath(child);
user.setFilename(filename);
 
upload.renameTo(new File(path+File.separator+child+File.separator+filename);
 
return success;
}
 
 
 
public String getChileDirectory(File dir)
{
SimpleDateFormat sdf = new SimpleDateFormat(“yyyy-MM-dd”);
Date date = new Date();
String tima = sdf.format(date);
File newdir=new File(dir,time);
if(!newdir.exists())
{
newdir.mkdirs();
}
return time;
}
 

 

 

//下载
 
private InputStream inputstream;
private String oldfilename;
public String download()
{
User u  = (User)session.get(User.class,1);
String path = ServletActionContext.getServletContext().getRealPath(“WEB-INF/upload”);
oldfilename=u.getFileName();
inputstream=new File(path+File.sepoarator+u.getPath()+u.getFilename());
}
 
<result type=”stream”>
<param name=”inputName”>inputstream</param>
<param name=”contentType”>application/octet-stream</param>
<param " >name=”contentDisposition”>attachment;;filename=${@java.net.URLEncoder@encode(oldFileName,"utf-8")}</param>
这个要是写错了,就会出现下载文件是action那个问题

 

 

 

对了 记得写

1:建文件加个感叹号

2:静态方法

可是还有好多好多小问题啊比如现在也没解决的时间问题,比如还有照片显示不出来。。

 

猜你喜欢

转载自zhanghecheng.iteye.com/blog/2341682
今日推荐