1200字范文,内容丰富有趣,写作的好帮手!
1200字范文 > java注解接收上传文件 前台:Input type=file 后台获取文件内容用的是spring注解

java注解接收上传文件 前台:Input type=file 后台获取文件内容用的是spring注解

时间:2023-07-15 14:33:30

相关推荐

java注解接收上传文件 前台:Input type=file 后台获取文件内容用的是spring注解

当前位置:我的异常网» Java Web开发»前台:Input type="file" 后台获取文件内

前台:Input type="file" 后台获取文件内容用的是spring注解,当地环境上传图片是好的,发布到服务器上图片读取不到,求大神指点

网友分享于:-08-26浏览:0次

前台:Input type="file" 后台获取文件内容用的是spring注解,本地环境上传图片是好的,发布到服务器上图片读取不到,求大神指点!

前台

*

后台

@RequestMapping("/userMember_editShowShop.do")

publicvoiduserMember_editShowShop(@ModelAttributeShowShopshowShop,

HttpSessionsession,HttpServletRequestrequest,HttpServletResponseresponse,

ModelMapmap){

try{

if(null!=showShop){

if(null!=showShop.getId()){

Propertyuseruser=(Propertyuser)session.getAttribute("user");

showShop.setCreateBy(user.getId());

//上传的图片保存在showShop里面,用的是File对象

Filepicture=showShop.getPicture();

System.out.println("-----------------〉:"+picture.getAbsolutePath());

if(picture!=null){

Stringpath=Config.getInstance().getProperty("phoneRootPath");

if(path==null){

path="E:/jlx51/upload/";

}else{

if(!path.endsWith("/")){

path=path+"/";

}

path=path+System.currentTimeMillis()+".jpg";

}

try{

UploadUtils.saveTo(picture,path);

}catch(IOExceptione){

e.printStackTrace();

}

showShop.setPhoto(path);

}

showShopService.updateShowShop(showShop);

request.getRequestDispatcher("userMember_getShowShopList.do").forward(request,response);

}

}

}catch(Exceptione){

e.printStackTrace();

}

}

publicstaticvoidsaveTo(Filefile,Stringpath)throwsIOException{

byte[]data=FileUtils.readFileToByteArray(file);

Filef=newFile(path);

if(f.exists()){

f.delete();

}

if(!f.getParentFile().exists()){

f.getParentFile().mkdirs();

}

FileUtils.writeByteArrayToFile(f,data);

}

服务器报的错误是:

java.io.FileNotFoundException:File'123.jpg'doesnotexist

mons.io.FileUtils.openInputStream(FileUtils.java:136)

mons.io.FileUtils.readFileToByteArray(FileUtils.java:994)

atcom.jlx51.utils.UploadUtils.saveTo(UploadUtils.java:15)

atcom.jlx51.config.spring.mvc.ShowShopController.userMember_insertShowShop(ShowShopController.java:108)

atsun.reflect.NativeMethodAccessorImpl.invoke0(NativeMethod)

atsun.reflect.NativeMethodAccessorImpl.invoke(UnknownSource)

atsun.reflect.DelegatingMethodAccessorImpl.invoke(UnknownSource)

atjava.lang.reflect.Method.invoke(UnknownSource)

atorg.springframework.web.bind.annotation.support.HandlerMethodInvoker.invokeHandlerMethod(HandlerMethodInvoker.java:176)

atorg.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter.invokeHandlerMethod(AnnotationMethodHandlerAdapter.java:440)

拿到的picturePath是服务器tomcat下的路径,根本不存在:E:\www\tomcat6.0.29\Tomcat6.0\123.jpg

求大神指点!

------解决思路----------------------

你获取picture的时候,是Filepicture=showShop.getPicture();请问这里你确定文件是封装到showShop对象的picture属性中了吗?spring注解文件上传参考这里

文章评论

java注解接收上传文件 前台:Input type=file 后台获取文件内容用的是spring注解 当地环境上传图片是好的 发布到服务器上图片读取不到 求大神指点...

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。