//文件上传需要的参数 private File upload;//上传的文件 upload和在jsp文件input type="file" name="upload"name一样 private String uploadFileName;//接收文件上传的文件名 private String uploadContextType;//接收文件上
private File upload;//上传的文件 upload和在jsp文件<input type="file" name="upload">name一样
private String uploadFileName;//接收文件上传的文件名
private String uploadContextType;//接收文件上传的类型
//判断文件是否为空
if(upload!=null){
//获取文件路径
String realPath=ServletActionContext.getServletContext().getRealPath("/products");
//创建一个文件
File diskFile=new File(realPath+"//"+uploadFileName);
FileUtils.copyFile(upload, diskFile);//将获得文件copy到出创建的diskFile文件中
product.setImage("products/"+uploadFileName);//设置图片路径