请教各位问题:java web客户端上传图片到服务器的D盘下,请问客户端怎么通过http访问图片

Python09

请教各位问题:java web客户端上传图片到服务器的D盘下,请问客户端怎么通过http访问图片,第1张

如果想让tomcat服务器访问指定磁盘 上的静态资源,可在tomcat/conf/server.xml中查找<Host></Host>,在标签中添加如下标签<Context path="/file" docBase="D:/img" reloadable="true"/>,再通过localhost:8080/file地址来访问路境内的文件:

如要访问名为d:/img/cat.png的图片,则localhost:8080/file/cat.png

这是因为..getInputStream().你想..你现在是从URL 里获取一个流对吧..URL 是网络的概念.网络传输数据是需要时间的.你的字节可能还没完全传输完,这时候,你就开始了你后面的传送业务逻辑..当然是不完整的.

        private File myfile

private String myfileFileName

private String myfileContentType

@Override

public String execute() throws Exception {

System.out.println("myfile---"+myfile)

System.out.println("myfileFileName---"+myfileFileName)

System.out.println("myfileContentType---"+myfileContentType)

ServletContext sc = ServletActionContext.getServletContext()

String path = sc.getRealPath("/file")

File newFile = new File(path+"/"+myfileFileName)

FileUtils.copyFile(myfile,newFile)

return null

}