求解虚拟主机中图片上传路径错误

在线电影网站上线半个多月了,磨磨蹭蹭的也解决了一些问题。

很多时候系统在本地是没有问题的,生产环境下却问题百出,比如后台的系统信息采集引擎出问题,

相同的影视资源有采集却不更新,俗话说网站内容是王啊,这个问题必须排第一位。

 

有的时候考虑网站除了广告收入是否还有其他模式的收入呢?

百思不得其解,理论上一切都在变,相同的模式不一定总是长青树。

曾经的报纸现在却没落了,FACEBOOK异军突起,所以要保持百思的势头,

哪天想到了新的互联网模式,能跟QQ并驾齐驱了(YY下

 

在没想到新模式之前吃饭还是要靠广告了,今天在网站后台上传了广告图片,却意外发现上传功能不能用

马上在本地测试,没问题,并调出了系统日志

 

java.io.FileNotFoundException: v0/hangzhouvedio/webapps/ROOT/advertis_files/20101229130615.jpg (Permission denied)
	at java.io.FileOutputStream.open(Native Method)
	at java.io.FileOutputStream.<init>(FileOutputStream.java:179)
	at java.io.FileOutputStream.<init>(FileOutputStream.java:131)
	at com.wang.vedio.util.dwr.AdvertistDwr.imgUpLoad(AdvertistDwr.java:38)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
	at java.lang.reflect.Method.invoke(Method.java:597)
	at org.directwebremoting.impl.DefaultRemoter$1.doFilter(DefaultRemoter.java:740)
	at org.directwebremoting.impl.DefaultRemoter.execute(DefaultRemoter.java:744)
	at org.directwebremoting.impl.DefaultRemoter.execute(DefaultRemoter.java:593)
	at org.directwebremoting.dwrp.BaseCallHandler.handle(BaseCallHandler.java:90)
	at org.directwebremoting.servlet.UrlProcessor.handle(UrlProcessor.java:120)
	at org.directwebremoting.servlet.DwrServlet.doPost(DwrServlet.java:141)
	at javax.servlet.http.HttpServlet.service(HttpServlet.java:637)
	at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
	at com.wang.vedio.util.filter.CharacterFilter.doFilter(CharacterFilter.java:21)
	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
	at org.tuckey.web.filters.urlrewrite.UrlRewriteFilter.doFilter(UrlRewriteFilter.java:738)
	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
	at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)
	at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
	at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:128)
	at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
	at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
	at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:286)
	at org.apache.jk.server.JkCoyoteHandler.invoke(JkCoyoteHandler.java:190)
	at org.apache.jk.common.HandlerRequest.invoke(HandlerRequest.java:283)
	at org.apache.jk.common.ChannelSocket.invoke(ChannelSocket.java:767)
	at org.apache.jk.common.ChannelSocket.processConnection(ChannelSocket.java:697)
	at org.apache.jk.common.ChannelSocket$SocketConnection.runIt(ChannelSocket.java:889)
	at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:690)
	at java.lang.Thread.run(Thread.java:619)

 

根据错误信息来看是没有操作权限了,网站部署在虚拟空间上,服务器用的是LINUX,对于这种环境下获取路径该怎么办呢?请路过的大虾们留下宝贵的意见

 

另,本地测试的系统编码没有问题,上传功能可以实现,把上传代码也贴出来吧

public String imgUpLoad(FileTransfer upfile, String filename){
		try{
			InputStream is = upfile.getInputStream();
			byte[] buffer = new byte[is.available()];
			if(is.available() == 0){
				return "图片为空请重试!";
			}
			if(upfile.getMimeType().indexOf("image") == -1){
				return "请上传图片类型文件!";
			}
			String file_name = null;
			if(filename == null || "".equals(filename)){//是否自定义文件名
				SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMddHHmmss");
				file_name = sdf.format(new Date());
			}else{
				file_name = filename;
			}
			String url = Thread.currentThread().getContextClassLoader().getResource("").getPath();
			String dir = url.substring(1, url.indexOf("WEB-INF")-1).replaceAll("%20", " ");//保存图片的根路径
			file_name = file_name + upfile.getFilename().substring(upfile.getFilename().lastIndexOf("."));
			file_name = "/imgage/advertis/" + file_name;//需要保存数据库的路径+文件名,用于页面访问
			FileOutputStream output = new FileOutputStream(new File(dir + file_name));//这里是第38行,就这里出错
			is.read(buffer);
			output.write(buffer);
			output.flush();
			output.close();
			is.close();
			return file_name;
		}catch(Exception e){
			e.printStackTrace();
			return "上传出错";
		}
		
	}

 

你可能感兴趣的:(java,apache,servlet,DWR,影视)