我是初学者,进行到JSP上传文件时遇到一点错误,直接不会了,求助啊-----
代码如下:
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<%@page import="org.lxh.smart.*" %>
<%@page import="IPTimeStamp.IPTimeStamp"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Smartupload</title>
</head>
<body>
<%
SmartUpload s = new SmartUpload();
s.initialize(pageContext);
s.upload();
String name = s.getRequest().getParameter("name");
IPTimeStamp itp = new IPTimeStamp(request.getRemoteAddr());
String ext = s.getFiles().getFile(0).getFileExt();
String filename = itp.getipstamp()+"."+ext;
s.getFiles().getFile(0).saveAs(this.getServletContext().getRealPath("/")+"smartupload"+java.io.File.separator+"upload"+java.io.File.separator+filename);
//s.save("E:\\Study\\workspace\\j2ee\\WebRoot\\smartupload\\upload\\");
//System.out.println(this.getServletContext().getRealPath("/"));
%>
name : <h3><%=filename %></h3>
<img src="../ipload/<%=filename %>">
</body>
</html>
部分错误提示如下:
SEVERE: Servlet.service() for servlet jsp threw exception
org.lxh.smart.SmartUploadException: File can't be saved (1120).
------解决思路----------------------
s.getFiles().getFile(0).saveAs(this.getServletContext().getRealPath("/")+"smartupload"+java.io.File.separator+"upload"+java.io.File.separator+filename);
改成
s.getFiles().getFile(0).saveAs(this.getServletContext().getRealPath("/")+java.io.File.separator+"smartupload"+java.io.File.separator+"upload"+java.io.File.separator+filename);