1.从Jsp页面提取上传的图片信息upload,<s:from>里要加 enctype="multipart/form-data"属性,上传的图片name="upload" type="file"
2.图片上传到指定路径(其中我上传的是到服务器下文件夹,并保存路径为image/products/***)
private String imageFileName;
private String imageContentType="jpg";
public String save() throws IOException{
//上传封面图片到服务器
Date currentTime = new Date();
SimpleDateFormat formatter = new SimpleDateFormat("yyyyMMddHHmmss");
String dateString = formatter.format(currentTime);
imageFileName = dateString;
String realpath = "G:\\WorkPlace\\shop\\WebRoot\\images\\products"; //可更换
System.out.println("realpath:"+realpath);
if(upload!=null){
File savefile = new File(new File(realpath),imageFileName+"."+imageContentType);
if(!savefile.getParentFile().exists())
savefile.getParentFile()