用jsmartcom上传图片传到tomcat上去了,怎么存到项目文件夹中? 5
这个是源码<%request.setCharacterEncoding("gbk");Stringdate=BaseDao.getDate();SmartUploadsm...
这个是源码
<%
request.setCharacterEncoding("gbk");
String date = BaseDao.getDate();
SmartUpload sma=new SmartUpload();
long file_max_size=4000000;
String filename1="",ext="",testvar="",filename="";
String url= "/upload";
sma.initialize(pageContext);
String photoName = "";
String photoContent = "";
try
{
sma.setAllowedFilesList("jpg,gif");
sma.upload();
sma.initialize(this.getServletConfig(), request, response);
photoName = sma.getRequest().getParameter("txtPhotoName");
photoContent = sma.getRequest().getParameter("txtDescription");
}catch(Exception e){
%>
<script language="jscript">
alert("只允许上传jpg,gif图片")
window.location.href="addService.jsp"
</script>
<%
}
try{
com.jspsmart.upload.File myf=sma.getFiles().getFile(0);
if(myf.isMissing()){
%>
<script language="jscript">
alert("请选择要上传的文件!")
window.location.href="addService.jsp"
</script>
<%
}else{
ext=myf.getFileExt();
int file_size=myf.getSize();
String saveurl="";
if(file_size < file_max_size){
Calendar cal=Calendar.getInstance();
filename=String.valueOf(cal.getTimeInMillis());
saveurl=request.getRealPath("/upload")+url;
saveurl+=filename+"."+ext;
myf.saveAs(saveurl,sma.SAVE_PHYSICAL);
}
}
}catch(Exception e){
e.printStackTrace();
}
上传显示成功了,但是在项目upload文件夹中找不到图片,
在tomcat,服务器文件夹里的upload文件夹里找到了..
但是我想存的地方是项目文件夹中,高手请指教下!
成功帮忙补送50分! 展开
<%
request.setCharacterEncoding("gbk");
String date = BaseDao.getDate();
SmartUpload sma=new SmartUpload();
long file_max_size=4000000;
String filename1="",ext="",testvar="",filename="";
String url= "/upload";
sma.initialize(pageContext);
String photoName = "";
String photoContent = "";
try
{
sma.setAllowedFilesList("jpg,gif");
sma.upload();
sma.initialize(this.getServletConfig(), request, response);
photoName = sma.getRequest().getParameter("txtPhotoName");
photoContent = sma.getRequest().getParameter("txtDescription");
}catch(Exception e){
%>
<script language="jscript">
alert("只允许上传jpg,gif图片")
window.location.href="addService.jsp"
</script>
<%
}
try{
com.jspsmart.upload.File myf=sma.getFiles().getFile(0);
if(myf.isMissing()){
%>
<script language="jscript">
alert("请选择要上传的文件!")
window.location.href="addService.jsp"
</script>
<%
}else{
ext=myf.getFileExt();
int file_size=myf.getSize();
String saveurl="";
if(file_size < file_max_size){
Calendar cal=Calendar.getInstance();
filename=String.valueOf(cal.getTimeInMillis());
saveurl=request.getRealPath("/upload")+url;
saveurl+=filename+"."+ext;
myf.saveAs(saveurl,sma.SAVE_PHYSICAL);
}
}
}catch(Exception e){
e.printStackTrace();
}
上传显示成功了,但是在项目upload文件夹中找不到图片,
在tomcat,服务器文件夹里的upload文件夹里找到了..
但是我想存的地方是项目文件夹中,高手请指教下!
成功帮忙补送50分! 展开
1个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询