日期:2014-05-17  浏览次数:21076 次

图片上传问题。。求解。
1.在iframe中有一个jsp页面。负责上传图片
<tr bgcolor="#FFFFFF">
  <td height="49" bgcolor="#799AE1" class="STYLE4"><div align="center"><span class="style2 STYLE5">图&nbsp; 片:</span></div></td>
  <td colspan="2" bgcolor="#799AE1"><input type="hidden" name="proimage" maxsize="100" size="60"> 
<iframe frameborder=0 width="400" height="39" scrolling=no src=manage/ad_uploadpro.jsp></iframe>
</td>
2.ad_uploadpro.jsp
<table border="0" cellpadding="0" cellspacing="0">  
<tr>  
<td valign="middle">
<form action="ad_uploadpro2.jsp" method="post" enctype="multipart/form-data" name="form1">  
<input type="file" name="file">  
<input type="submit" name="Submit" value="上传">  
</form></td>  
</tr>  
</table>  

3.ad_uploadpro.jsp提交到ad_uploadpro2.jsp处理。我怎么获取这个图片的 pic/filename.jpg这个路径插入oracle数据库。


  </head>
  <%  
SmartUpload mySmartUpload =new SmartUpload();  
long file_size_max=4000000;  
String fileName2="",ext="",testvar="";  
String url="manage/pic/"; //应保证在根目录中有此目录的存在(也就是说需要自己建立相应的文件夹)  
//初始化  
mySmartUpload.initialize(pageContext);  
//只允许上载此类文件  
try {  
mySmartUpload.setAllowedFilesList("jpg,gif");//此处的文件格式可以根据需要自己修改  
//上载文件  
mySmartUpload.upload();  
} catch (Exception e){  
%>  
<SCRIPT language=javascript>  
alert("只允许上传.jpg和.gif类型图片文件");  
window.location='upload.jsp';  
</script>
<%  
}  
try{  
  
com.jspsmart.upload.File myFile = mySmartUpload.getFiles().getFile(0);  
if (myFile.isMissing()){%>
<SCRIPT language=javascript>  
alert("请先选择要上传的文件");  
window.location='ad_uploadpro.jsp';  
</script>
<%}  
else{  
//String myFileName=myFile.getFileName(); //取得上载的文件的文件名  
ext= myFile.getFileExt(); //取得后缀名  
int file_size=myFile.getSize(); //取得文件的大小  
String saveurl="";  
if(file_size<file_size_max){  
//更改文件名,取得当前上传时间的毫秒数值  
Calendar calendar = Calendar.getInstance();  
String filename = String.valueOf(calendar.getTimeInMillis());  
saveurl=application.getRealPath("/")+url; 
//saveurl = request.getSession().getServletContext().getRealPath("/");


 
saveurl+=filename+"."+ext; //保存路径  
myFile.saveAs(saveurl,SmartUpload.SAVE_PHYSICAL);  
out.print(saveurl);  
  
//String ret = "parent.HtmlEdit.focus();";  
//ret += "var range = parent.HtmlEdit.document.selection.createRange();" ;  
//ret += "range.pasteHTML('<img src=\"" + request.getContextPath() + "/pic/" + filename + "." + ext + "\">');" ;  
//ret += "alert('上传成功!');";  
//ret += "window.location='upload.jsp';";  
//out.print("<script language=javascript>" + ret + "</script>"); 
//out.print(ret);
//out.print(