首页 新闻 搜索 专区 学院

tomcat 自动删除上传文件?有人见过??

1
悬赏园豆:10 [待解决问题]

servlet----------------------

Questionbank qb=new Questionbank();
qb.setQuestion(request.getParameter("question"));
qb.setOptionA(request.getParameter("optionA"));
qb.setOptionB(request.getParameter("optionB"));
qb.setOptionC(request.getParameter("optionC"));
qb.setOptionD(request.getParameter("optionD"));
qb.setAnswer(request.getParameter("answer").charAt(0));

Part part=request.getPart("image");
if(part.getSize()!=0){
String header = part.getHeader("content-disposition");
String filename=UUID.randomUUID().toString()+"."+this.getExt(header);
qb.setImage(filename);
//保存图片
String storePath = request.getServletContext().getRealPath("/uploadFile");
//把文件写到指定路径
File f=new File(storePath+File.separator);
if(!f.exists()){
f.mkdirs();
}
try{
part.write(storePath+File.separator+filename);
}catch(IOException e){
e.printStackTrace();
}finally{
if(part!=null)
part.delete();
}
}else{
qb.setImage("");
}
qb.setAnalysis(request.getParameter("analysis"));
qbImpl.save(qb);

------------------------------------------------

$("form").ajaxForm({
url:"<%=request.getContextPath()%>/PracticeServlet",
type:"post",
enctype:"multipart/form-data",
iframe:true,
dataType:"text",
success:function(data) {
alert(data);
$("input[type='button'][value='重设']").click();
},
error:function(data) {
alert("出错!");
}
});

泥沙时代的主页 泥沙时代 | 初学一级 | 园豆:165
提问于:2013-11-29 12:46
< >
分享
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册