2个回答
展开全部
页面的form
<form action="indexDetail.action" method="post" enctype="multipart/form-data">
图片:<input type="file" name="file" /><br />
<input type="submit" name="imageField" class="btn_img img_submit" value="提交" />
</form>
后台代码
// 上传文件
private File file;
private String fileFileName;
String realpath = ServletActionContext.getServletContext().getRealPath("/images/ask/");
if (!new File(realpath).exists()) {
new File(realpath).mkdir();
}
String[] typechoose = fileFileName.split("\\.");
int ichoose = typechoose.length;
String type = ichoose>1?typechoose[ichoose-1]:"";
SimpleDateFormat smat = new SimpleDateFormat("yyyyMMddHHmmss");
String newfilname = smat.format(new Date())+"."+type;
String path = realpath+"/"+newfilname;
FileUtil.saveFile(path, file);
核心代码都在里面
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询