为什么上传的图片在电脑文件夹看不到,在Tomcat服务器却可以看到? 从html表发送到jsp表,然后保存在文件夹里面,在电脑的文件夹看不到上传的图片,而在Tomcat服务器却可以看到,不懂是什么原因,有人和我一样情况的吗? 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 开发的项目是开发的项目,运行的项目是运行的项目,开发的项目可以发布到运行项目上去,你在tomcat服务器环境中运行的项目,上传的文件,用相对地址保存,保存的路径当然是tomcat中。没在你开发的项目中。 //定义上传路劲 String path = request.getSession().getServletContext().getRealPath("/uploadImg"); String reelPath = path+"/"+newName; pth="/uploadImg/"+newName; File localFile = new File(path);上传的路径一般都是根据相对路径进行上传的 如果你要指定绝对路径 则需要自己定义好 你的项目是在tomcat中运行的话,你保存文件如果采取相对路径,他是根据你的项目位置进行作为根目录,所以你的图片会在tomcat中 我设置了路径了。上传的时候说找不到路径,不知道怎么回事。<% request.setCharacterEncoding("UTF-8"); //实例化对象 SmartUpload smart = new SmartUpload(); //设置SmartUpload环境 smart.initialize(config, request, response); //接收html表传过来的内容 smart.upload(); //有上传内容才可以保存 if(smart.getFiles().getSize()>0){ for(int x = 0;x<smart.getFiles().getCount();x++){ //只有图片类型才能进行保存 if(smart.getFiles().getFile(x).getContentType().contains("image")){ if(smart.getFiles().getFile(x).getSize()>0){ //给图片重新命名 String fileName = UUID.randomUUID() + "." + smart.getFiles().getFile(x).getFileExt(); //设置保存的路径 String filePath = getServletContext().getRealPath("/upload/")+ fileName; //保存上传信息 smart.getFiles().getFile(x).saveAs(filePath); } }%> 设置的路径是在webApp下的upload吧?有这个文件夹么 你可以把filePath 打印出来看一下,这样你就知道你的这个路径是不是有误 JSP 网上商城产品添加为什么会报错?? TabPane选项卡的问题 地址栏的验证问题?? 如何用javascript实现异同校验? 页面上的地址一般是填相对地址好还是绝对地址好 关于<c:set>无法传递变量值的问题 新手学习jsp 高手帮我看看这个问题 这样调用excel? 郁闷得数据库问题!达人乱入 springmvc forward请求转发出错,求助 在Eclipse里.java文件会自动编译吗,各位前辈指导下
String path = request.getSession().getServletContext().getRealPath("/uploadImg");
String reelPath = path+"/"+newName;
pth="/uploadImg/"+newName;
File localFile = new File(path);上传的路径一般都是根据相对路径进行上传的 如果你要指定绝对路径 则需要自己定义好
我设置了路径了。上传的时候说找不到路径,不知道怎么回事。
<%
request.setCharacterEncoding("UTF-8");
//实例化对象
SmartUpload smart = new SmartUpload();
//设置SmartUpload环境
smart.initialize(config, request, response);
//接收html表传过来的内容
smart.upload();
//有上传内容才可以保存
if(smart.getFiles().getSize()>0){
for(int x = 0;x<smart.getFiles().getCount();x++){
//只有图片类型才能进行保存
if(smart.getFiles().getFile(x).getContentType().contains("image")){
if(smart.getFiles().getFile(x).getSize()>0){
//给图片重新命名
String fileName = UUID.randomUUID() + "." + smart.getFiles().getFile(x).getFileExt();
//设置保存的路径
String filePath = getServletContext().getRealPath("/upload/")+ fileName;
//保存上传信息
smart.getFiles().getFile(x).saveAs(filePath);
}
}
%>