当前位置: 代码迷 >> Java Web开发 >> java.lang.IllegalArgumentException: This path does not exist
  详细解决方案

java.lang.IllegalArgumentException: This path does not exist

热度:782   发布时间:2016-04-17 12:32:52.0
为什么我用上传组件上传文件或是图片报错呀,
<%@page contentType="text/html; charset=GBK"%>
<html>
<head>
<title>jsp2</title>
</head>
<body bgcolor="#ffffff">
<h1>JBuilder Generated JSP</h1>
<form name="form1" method="post" action="jsp2.jsp" enctype="multipart/form-data">
<table width="75%" border="0" align="center" cellpadding="0" cellspacing="0" class=table2 bgcolor="#FFFFFF">
  <tr>
  <td align="right">图片:</td>
  <td>
  <input name="tp" type="file" id="tp" size="57">
  </td>
  </tr>
  <tr align="center" valign="middle">
  <td height="30" colspan="2">
  <input type="submit" name="tj" value="提交" class=button>
  &nbsp;
  <input type="reset" name="cz" value="重置" class=button>
  &nbsp;
  </td>
  </tr>
</table>
</form>
</body>
</html>






处理页面:
<%@page contentType="text/html; charset=gb2312"%>
<%@page import="java.sql.*"%>
<%@page import="java.util.*"%>
<%@page import="com.jspsmart.upload.*"%>
<%
try
{
  //conn conn = new conn();
  SmartUpload mySmartUpload = new SmartUpload();
  mySmartUpload.initialize(pageContext);
  Files fs = mySmartUpload.getFiles();
  mySmartUpload.upload();
  String tp = mySmartUpload.getRequest().getParameter("tp");
  File f;
  for (int i = 0; i < fs.getCount(); i++) {
  f = fs.getFile(i);
  String path = "/sc/xxfb/";
  if (f.getFileName().length() > 0) {
  if (i == 0) {
  String filename = "mypic" + f.getFileName().substring(f.getFileName().lastIndexOf("."), f.getFileName().length());
  f.saveAs(path + filename);
  tp = filename;
  }
  }
  }
  if (tp == null) {
  tp = "null";
  }
  //conn.sqlInsert("insert into xxfb values('" + id + "','" + bt + "','" + tp + "')");
  //conn.close();
  out.println(tp);
}
catch(Exception e)
{
  e.printStackTrace();
}
%>


运行之后点击提交:
报这种错:java.lang.IllegalArgumentException: This path does not exist (1135).

哪位高手,帮我看看好吗,求助!!!

------解决方案--------------------
哎呀,你没有这个路径,你要保存的路径!
绝对路径比如:c:/sc/xxfb/文件名(带后缀名)
------解决方案--------------------
String path = "/sc/xxfb/"; 这个是相对路径,你在/sc/xxfb这个文件夹不存在,你建立一个就好了
  相关解决方案