我的项目在本地测试 上传图片可以的。 当我把项目放到空间管理上,上传图片 就会报错。
HTTP Status 500 - type Exception reportmessage description The server encountered an internal error () that prevented it from fulfilling this request.exception javax.servlet.ServletException: /home/keyeneta/public_html/upload/picture/1310979577207.jpg (Permission denied)
org.apache.struts2.dispatcher.Dispatcher.serviceAction(Dispatcher.java:518)
org.apache.struts2.dispatcher.FilterDispatcher.doFilter(FilterDispatcher.java:421)
org.springframework.orm.hibernate3.support.OpenSessionInViewFilter.doFilterInternal(OpenSessionInViewFilter.java:174)
org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:77)
org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:72)
org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:78)
org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:77)
root cause java.io.FileNotFoundException: /home/keyeneta/public_html/upload/picture/1310979577207.jpg (Permission denied)
java.io.FileOutputStream.open(Native Method)
java.io.FileOutputStream.<init>(FileOutputStream.java:179)
java.io.FileOutputStream.<init>(FileOutputStream.java:70)
com.tcc.system.common.UploadFile.upload(UploadFile.java:37)
com.tcc.system.common.UploadFile.uploadPic(UploadFile.java:91)
com.tcc.system.action.AdminProSet.addSave(AdminProSet.java:270)
sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
这段代码实现上传图片 public static String uploadPic(File upload, String fileName)
throws Exception {
String resPath = new Admin().getClass().getResource("/").toString();
resPath = resPath.substring(6,resPath.length()-17);
String name ="/upload/picture/" + System.currentTimeMillis() + "."
+ StringUtil.getSux(fileName);
String path = ServletActionContext.getServletContext().getRealPath("/")
+ name; upload(path, upload);
return name;
}

解决方案 »

  1.   

    java.io.FileNotFoundException: /home/keyeneta/public_html/upload/picture/1310979577207.jpg (Permission denied)
    文件没有发现吧 
      

  2.   

    java.io.FileNotFoundException: /home/keyeneta/public_html/upload/picture/1310979577207.jpg (Permission denied)文件夹找不到,
    你的路径设置有问题。
    检查下。
      

  3.   

    我推荐使用Thread.currentThread().getContextClassLoader().getResource("")来得到当前的classpath的绝对路径的URI表示法。
      

  4.   

      问题解解决了, 谢谢各位的建议,
    我的问题是在 FTP上的该目录下的 权限问题  修改好权限 问题就解决了