日期:2014-05-20  浏览次数:20902 次

url==/WebFriend/userimg/1307029058093.jpgjava.lang.IllegalArgumentExcept
url==/WebFriend/userimg/1307029058093.jpgjava.lang.IllegalArgumentException: This path does not exist (1135).
这是代码..就是在file.saveAs这边会出错,我想不通了我工程路径是对的,也有这个文件夹..为什么它老是报错 
<%@ page contentType="text/html; charset=gb2312" language="java" %>
<%@page import="java.util.*" %> 
<%@page import="java.sql.*" %> 
<%@page import="java.io.*" %> 
<%@page import="com.jspsmart.upload.*" %> 
<%@page import="java.awt.*" %> 
<%@page import="java.awt.image.*" %> 
<%@page import="com.sun.image.codec.jpeg.*" %> 

<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<html>
<head>
<title>文件上传处理页面</title>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
</head>

<body>
<%
try
{
String url= "jdbc:mysql://localhost:3306/message";
String user="root";
String password="root"; 

  SmartUpload su = new SmartUpload();
  su.initialize(pageContext);
  su.setMaxFileSize(2000000);
  su.setTotalMaxFileSize(20000000);
  su.setAllowedFilesList("jpg,gif,bmp,png");
  su.upload();
  for (int i=0;i<su.getFiles().getCount();i++)
  {
  com.jspsmart.upload.File file = su.getFiles().getFile(i);
  if (file.isMissing()) continue;
  java.util.Date d =new java.util.Date();
  Long l = d.getTime();
  System.out.print("url=="+request.getContextPath()+"/userimg/" +l.toString()+ "."+file.getFileExt());
  file.saveAs(request.getContextPath()+"/userimg/" +l.toString()+ "."+file.getFileExt());
  java.io.File yuan = new java.io.File(request.getContextPath()+"/userimg/" +"\\"+l.toString()+ "."+file.getFileExt()); //读入刚才上传的文件
  System.out.print(yuan);
  String newurl=request.getContextPath()+"/userimg/" +"\\"+l.toString()+ "_s."+file.getFileExt(); //新的缩略图保存地址
  Image src = javax.imageio.ImageIO.read(yuan); //构造Image对象
  int new_w=150;
  int new_h=150;
  BufferedImage tag = new BufferedImage(new_w,new_h,BufferedImage.TYPE_INT_RGB);
  tag.getGraphics().drawImage(src,0,0,new_w,new_h,null); //绘制缩小后的图
  FileOutputStream newimage=new FileOutputStream(newurl); //输出到文件流
  JPEGImageEncoder encoder = JPEGCodec.createJPEGEncoder(newimage);  
  encoder.encode(tag); //近JPEG编码
  newimage.close();  
out.print("id======="+Integer.parseInt(session.getAttribute("id").toString()));  
String opath=request.getContextPath()+"/userimg/"+l.toString()+ "."+file.getFileExt();
  String spath=request.getContextPath()+"/userimg/"+l.toString()+ "_s."+file.getFileExt();

  request.setCharacterEncoding("gb2312");
  Class.forName("com.mysql.jdbc.Driver"); //载入JDBC驱动程序
  Connection conn=DriverManager.getConnection(url,user,password);; //创建数据库连接对象
  PreparedStatement stmt=conn.prepareStatement("update user_table set userImg =? where id="+Integer.parseInt(session.getAttribute("id").toString()));