jsp使用SmartUpload组件组件上传图片,页面显示上传成功,却没出现在相应的文件夹
上传图片到根目录文件夹upload下,程序运行完成没有错误但是upload文件夹里面没有图片,,我已经在当前目录下建了upload文件夹了,也有导入SmartUpload...
上传图片到根目录文件夹upload下,程序运行完成没有错误但是upload文件夹里面没有图片,,我已经在当前目录下建了upload文件夹了,也有导入SmartUpload,程序没有报错,
但是,上传后,upload文件夹里没有图片
代码:
<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<base href="<%=basePath%>">
<title>My JSP 'upload.jsp' starting page</title>
</head>
<body>
<p align="center">上传文件附加信息</p>
<form method="post" action ="do_upload.jsp" enctype="multipart/form-data">
<table width="90%" align="center" border="1">
<tr>
<td>
<div align="center">产品图片:
<input type="file" name="file1" size=30>
</div>
</td> </tr> <tr>
<td>
<div align="center">产品说明:
<input type="file" name="file2" size=30>
</div>
</td> </tr> <tr>
<td>
<div align="center"><input type="submit" name="submit1" value="上传"></div>
</td> <tr>
</table> </form> </body>
</html>
-----------------------------------------------------------------------------------------------------
文件上传后跳转的页面
<%@ page language="java" import="java.util.*,com.jspsmart.upload.*" pageEncoding="UTF-8"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<base href="<%=basePath%>">
<title>My JSP 'do_upload.jsp' starting page</title>
</head>
<body>
<% SmartUpload su = new SmartUpload();
su.initialize(pageContext);
su.upload();
int count= su.save("/webapps/picture/upload",su.SAVE_VIRTUAL);
System.out.println(count);
out.println(count+"个文件上传成功<br>");
for(int i=0;i<su.getFiles().getCount(); i++){
com.jspsmart.upload.File file = su.getFiles().getFile(i);
if(file.isMissing()) continue;
out.print("<br>文件名:"+file.getFileName()+ "长度为:"+ file.getSize());
}
%>
</body>
</html>
int count= su.save("/webapps/picture/upload",su.SAVE_VIRTUAL);
这句话,写错了,
应该是 int count= su.save(”/upload",su.SAVE_VIRTUAL);才没有报错 展开
但是,上传后,upload文件夹里没有图片
代码:
<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<base href="<%=basePath%>">
<title>My JSP 'upload.jsp' starting page</title>
</head>
<body>
<p align="center">上传文件附加信息</p>
<form method="post" action ="do_upload.jsp" enctype="multipart/form-data">
<table width="90%" align="center" border="1">
<tr>
<td>
<div align="center">产品图片:
<input type="file" name="file1" size=30>
</div>
</td> </tr> <tr>
<td>
<div align="center">产品说明:
<input type="file" name="file2" size=30>
</div>
</td> </tr> <tr>
<td>
<div align="center"><input type="submit" name="submit1" value="上传"></div>
</td> <tr>
</table> </form> </body>
</html>
-----------------------------------------------------------------------------------------------------
文件上传后跳转的页面
<%@ page language="java" import="java.util.*,com.jspsmart.upload.*" pageEncoding="UTF-8"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<base href="<%=basePath%>">
<title>My JSP 'do_upload.jsp' starting page</title>
</head>
<body>
<% SmartUpload su = new SmartUpload();
su.initialize(pageContext);
su.upload();
int count= su.save("/webapps/picture/upload",su.SAVE_VIRTUAL);
System.out.println(count);
out.println(count+"个文件上传成功<br>");
for(int i=0;i<su.getFiles().getCount(); i++){
com.jspsmart.upload.File file = su.getFiles().getFile(i);
if(file.isMissing()) continue;
out.print("<br>文件名:"+file.getFileName()+ "长度为:"+ file.getSize());
}
%>
</body>
</html>
int count= su.save("/webapps/picture/upload",su.SAVE_VIRTUAL);
这句话,写错了,
应该是 int count= su.save(”/upload",su.SAVE_VIRTUAL);才没有报错 展开
2个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询