这里我试图将图像上传到在线这个代码在本地工作正常,但它在上传时显示异常。我正在使用apache coom文件上传库并使用eclipse作为java编辑器任何帮助。
例外:
43832_1048_1.jpgThumbnails /var/www/kreativ/data/www/7.kreativwebsolutions.com/ROOT/Thumbnails/43832_1048_1.jpg
if :: ListingURL缩略图java.io.FileNotFoundException: /tmp/upload__63fd8030_144fd30231a__7ffb_00000022.tmp (No such file or directory)
但我的根目录中有一个文件夹。
<%@ page import="java.util.List" %>
<%@ page import="java.util.Iterator,java.util.*" %>
<%@ page import="java.io.*" %>
<%@ page import="org.apache.commons.fileupload.servlet.ServletFileUpload"%>
<%@ page import="org.apache.commons.fileupload.disk.DiskFileItemFactory"%>
<%@ page import="org.apache.commons.fileupload.*"%>
<%@ page import="java.awt.image. BufferedImage"%>
<%@ page import="javax.imageio.ImageIO"%>
<jsp:useBean id="EST" class="beans.estate_agent_table"/>
<%
mainClasses.estate_agent_tableListing EST_CL = new mainClasses.estate_agent_tableListing();
List EST_List=EST_CL.getMestate_agent_table(session.getAttribute("AGENT_ID").toString());
if(EST_List.size()!=0){
EST=(beans.estate_agent_table)EST_List.get(0);}
boolean isMultipart = ServletFileUpload.isMultipartContent(request);
boolean falg=true;
int movieimage_count=0;
String AGENT_REF="";
String moviealbum_id="";
String FileName="";
String sale_let="";
if (!isMultipart) {
}else{
FileItemFactory factory = new DiskFileItemFactory();
ServletFileUpload upload = new ServletFileUpload(factory);
List items = null;
try {
items = upload.parseRequest(request);
} catch (FileUploadException e) {
out.print(e);
}
Iterator itr = items.iterator();
while (itr.hasNext()) {
FileItem item = (FileItem) itr.next();
if (item.isFormField())
{
String name = item.getFieldName();
String value = item.getString();
if(name.equals("moviealbum_id"))
{
moviealbum_id=value;
}
if(name.equals("movieimage_count"))
{
movieimage_count=Integer.parseInt(value);
}
if(name.equals("propertyid"))
{
AGENT_REF=value;
}
if(name.equals("sale_let")){
sale_let= value;
}
}else{
try{
String itemName = item.getName();
int dotPos = itemName.lastIndexOf(".")+1;
String extension = itemName.substring(dotPos);
if(extension.equals("JPG") || extension.equals("jpg") || extension.equals("gif") || extension.equals("GIF") || extension.equals("JPEG") || extension.equals("jpeg") || extension.equals("PNG") || extension.equals("png"))
{
movieimage_count=movieimage_count+1;
FileName=AGENT_REF+"_"+movieimage_count+"."+extension;
}
if(!FileName.equals(""))
{
try
{
BufferedImage image = ImageIO.read( item.getInputStream() );
beans.ResizeImage RI=new beans.ResizeImage();
BufferedImage thumb=RI.ReSize(image,80);
out.println(FileName+"Thumbnails");
if( EST.getThumbnails()==null || EST.getThumbnails().equals("null") || EST.getThumbnails().equals("")){
item.write(new File(config.getServletContext().getRealPath("/")+"Thumbnails/"+FileName));
out.println(config.getServletContext().getRealPath("/")+"Thumbnails/"+FileName+"if::ListingURL");
}else{
item.write(new File(EST.getThumbnails()+"Thumbnails/"+FileName));
out.println(FileName+"else::FileName");
}
}
catch(Exception es){out.print("Thumbnails "+es);}
try
{
BufferedImage image = ImageIO.read( item.getInputStream() );
beans.ResizeImage RI=new beans.ResizeImage();
BufferedImage thumb=RI.ReSize(image,80);
out.println(FileName+"list");
if( EST.getThumbnails()==null || EST.getThumbnails().equals("null") || EST.getThumbnails().equals("")){
item.write(new File(config.getServletContext().getRealPath("/")+"list/"+FileName));
out.println(config.getServletContext().getRealPath("/")+"list/"+FileName+"if::list");
}else{
item.write(new File(EST.getThumbnails()+"list/"+FileName));
out.println(FileName+"else::FileName");
}
}
catch(Exception es){out.print("Thumbnails "+es);}
}
}
catch (Exception e) {
out.print(e);
falg=false;
}
}
}
}
%>