JSP写的上传文件时出错 Files' name is invalid or does not exist (1205).求大神指导
用的JspSmartUpload单独一个上传下载的项目可以成功复制到另一个项目中提示错误SEVERE:Servlet.service()forservlet[jsp]in...
用的JspSmartUpload 单独一个上传下载的项目可以成功 复制到另一个项目中提示错误
SEVERE: Servlet.service() for servlet [jsp] in context with path [/house] threw exception [java.lang.IllegalArgumentException: Files' name is invalid or does not exist (1205).] with root cause
java.lang.IllegalArgumentException: Files' name is invalid or does not exist (1205).
上传文件部分代码:
<%
String SubPath=this.getServletContext().getRealPath("/")+"upload";
File createSub=new File(SubPath);
if(!createSub.exists())createSub.mkdir();
upFile.initialize(pageContext);
upFile.setAllowedFilesList("txt,doc,xls,rar,mp3,");
upFile.setMaxFileSize(2000000);
upFile.upload();
Long size=upFile.getFiles().getSize();
if(size>2000000)
{
out.println("<script>alert('上传文件太大,无法完成上传');</script>");
}
else{
String filename=upFile.getFiles().getFile(0).getFileName();
upFile.save("/upload");
try{
String username="sa";
String password="123456";
Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
String url="jdbc:sqlserver://localhost:1433;DatabaseName=house";
Connection conn=DriverManager.getConnection(url,username,password);
String sql="insert into notice(title,contents,filename) values(?,?,?)";
PreparedStatement pstmt=conn.prepareStatement(sql);
pstmt.setString(1,upFile.getRequest().getParameter("title"));
pstmt.setString(2,upFile.getRequest().getParameter("contents"));
pstmt.setString(3,filename);
pstmt.execute();
pstmt.close();
out.println(upFile.getRequest().getParameter("title")+"添加成功!"); 展开
SEVERE: Servlet.service() for servlet [jsp] in context with path [/house] threw exception [java.lang.IllegalArgumentException: Files' name is invalid or does not exist (1205).] with root cause
java.lang.IllegalArgumentException: Files' name is invalid or does not exist (1205).
上传文件部分代码:
<%
String SubPath=this.getServletContext().getRealPath("/")+"upload";
File createSub=new File(SubPath);
if(!createSub.exists())createSub.mkdir();
upFile.initialize(pageContext);
upFile.setAllowedFilesList("txt,doc,xls,rar,mp3,");
upFile.setMaxFileSize(2000000);
upFile.upload();
Long size=upFile.getFiles().getSize();
if(size>2000000)
{
out.println("<script>alert('上传文件太大,无法完成上传');</script>");
}
else{
String filename=upFile.getFiles().getFile(0).getFileName();
upFile.save("/upload");
try{
String username="sa";
String password="123456";
Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
String url="jdbc:sqlserver://localhost:1433;DatabaseName=house";
Connection conn=DriverManager.getConnection(url,username,password);
String sql="insert into notice(title,contents,filename) values(?,?,?)";
PreparedStatement pstmt=conn.prepareStatement(sql);
pstmt.setString(1,upFile.getRequest().getParameter("title"));
pstmt.setString(2,upFile.getRequest().getParameter("contents"));
pstmt.setString(3,filename);
pstmt.execute();
pstmt.close();
out.println(upFile.getRequest().getParameter("title")+"添加成功!"); 展开
2个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询