文件上传时出现 File can't be saved

gnod 2003-02-17 03:07:16
底下是错误信息,请高手指教,谢谢!

Error: 500
Location: /test01/sample2.jsp
Internal Servlet Error:

javax.servlet.ServletException: File can't be saved (1120).
at org.apache.jasper.runtime.PageContextImpl.handlePageException(PageContextImpl.java:460)
at test01.sample2_1._jspService(sample2_1.java:144)
at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:119)
at javax.servlet.http.HttpServlet.service(HttpServlet.java)
at org.apache.tomcat.facade.ServletHandler.doService(ServletHandler.java:574)
at org.apache.tomcat.core.Handler.invoke(Handler.java:322)
at org.apache.tomcat.core.Handler.service(Handler.java:235)
at org.apache.tomcat.facade.ServletHandler.service(ServletHandler.java:485)
at org.apache.tomcat.core.ContextManager.internalService(ContextManager.java:917)
at org.apache.tomcat.core.ContextManager.service(ContextManager.java:833)
at org.apache.tomcat.modules.server.Ajp13Interceptor.processConnection(Ajp13Interceptor.java:341)
at org.apache.tomcat.util.net.TcpWorkerThread.runIt(PoolTcpEndpoint.java:494)
at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:516)
at java.lang.Thread.run(Thread.java:536)
Root cause:
com.jspsmart.upload.SmartUploadException: File can't be saved (1120).
at com.jspsmart.upload.File.saveAs(File.java:108)
at com.jspsmart.upload.File.saveAs(File.java:65)
at test01.sample2_1._jspService(sample2_1.java:121)
at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:119)
at javax.servlet.http.HttpServlet.service(HttpServlet.java)
at org.apache.tomcat.facade.ServletHandler.doService(ServletHandler.java:574)
at org.apache.tomcat.core.Handler.invoke(Handler.java:322)
at org.apache.tomcat.core.Handler.service(Handler.java:235)
at org.apache.tomcat.facade.ServletHandler.service(ServletHandler.java:485)
at org.apache.tomcat.core.ContextManager.internalService(ContextManager.java:917)
at org.apache.tomcat.core.ContextManager.service(ContextManager.java:833)
at org.apache.tomcat.modules.server.Ajp13Interceptor.processConnection(Ajp13Interceptor.java:341)
at org.apache.tomcat.util.net.TcpWorkerThread.runIt(PoolTcpEndpoint.java:494)
at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:516)
at java.lang.Thread.run(Thread.java:536)

...全文
629 9 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
9 条回复
切换为时间正序
请发表友善的回复…
发表回复
gnod 2003-02-17
  • 打赏
  • 举报
回复
servlet.jar包需要另外加吗?请问那里有下载?
Robornet 2003-02-17
  • 打赏
  • 举报
回复
你缺少servlet.jar包或没有加入classpath中
gnod 2003-02-17
  • 打赏
  • 举报
回复
不好意思看错了,是路径不存在.

javax.servlet.ServletException: This path does not exist (1135).
gnod 2003-02-17
  • 打赏
  • 举报
回复
还是一样的错误
zxhong 2003-02-17
  • 打赏
  • 举报
回复
myFile.saveAs("/home/web/www/test01/" + myFile.getFileName());
---》
myFile.saveAs("home/web/www/test01/" + myFile.getFileName());


gnod 2003-02-17
  • 打赏
  • 举报
回复
import java.io.*;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.Vector;
import javax.servlet.*;
import javax.servlet.http.*;
import javax.servlet.jsp.JspWriter;
import javax.servlet.jsp.PageContext;
public class uploadBean {
protected byte m_binArray[] = null;
protected HttpServletRequest m_request = null;
protected HttpServletResponse m_response = null;
protected ServletContext m_application = null;
private int m_totalBytes = 0;
private int m_currentIndex = 0;
private int m_startData = 0;
private int m_endData = 0;
private String m_boundary = null;
public uploadBean() {
m_totalBytes = 0;
m_currentIndex = 0;
m_startData = 0;
m_endData = 0;
m_boundary = new String();
}
public final void init(ServletConfig config) throws ServletException {
m_application = config.getServletContext();
}
public void service(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException {
m_request = request;
m_response = response;
}
public final void initialize(ServletConfig config, HttpServletRequest request, HttpServletResponse response) throws ServletException {
m_application = config.getServletContext();
m_request = request;
m_response = response;
}
public final void initialize(PageContext pageContext) throws ServletException {
m_application = pageContext.getServletContext();
m_request = (HttpServletRequest)pageContext.getRequest();
m_response = (HttpServletResponse)pageContext.getResponse();
}
public void uploadData() throws IOException, ServletException {
int totalRead = 0;
int readBytes = 0;
boolean found = false;
String dataHeader = new String();
String fieldName = new String();
String fileName = new String();
String fileExt = new String();
String filePathName = new String();
String contentType = new String();
String contentDisp = new String();
String typeMIME = new String();
String subTypeMIME = new String();
java.io.FileOutputStream fileout=null;
java.io.FileOutputStream fileout2=null;
boolean isFile = false;
m_totalBytes = m_request.getContentLength();
m_binArray = new byte[m_totalBytes];
for(; totalRead < m_totalBytes; totalRead += readBytes)
try {
m_request.getInputStream();
readBytes = m_request.getInputStream().read(m_binArray, totalRead, m_totalBytes - totalRead);
} catch(Exception e) {
System.out.println(" Unable to upload data .");
e.printStackTrace();
}
System.out.println("------>totalRead:"+totalRead);
for(;!found && m_currentIndex < m_totalBytes;m_currentIndex++) {
if(m_binArray[m_currentIndex] == 13) found = true;
else m_boundary = m_boundary + (char)m_binArray[m_currentIndex];
}
if(m_currentIndex == 1) return;
m_currentIndex++;
do {
if(m_currentIndex >= m_totalBytes) break;
dataHeader = getDataHeader();
System.out.println(dataHeader);
m_currentIndex = m_currentIndex + 2;
isFile = dataHeader.indexOf("filename") > 0;
fieldName = getDataFieldValue(dataHeader, "name");
if(isFile) { //// } getDataSection();if(isFile) { ////
System.out.println("----->m_startData:"+m_startData);
System.out.println("----->m_endData:"+m_endData);
try {
fileout = new FileOutputStream("c:\\test11.doc");
fileout.write(m_binArray,m_startData,m_endData-m_startData+1);
fileout2 = new FileOutputStream("c:\\test00.doc");
fileout2.write(m_binArray);
} catch(Exception e) {
System.out.println(" Unable to write data to test file .");
e.printStackTrace();
} finally {
try {
fileout.close();
fileout2.close();
} catch(Exception e) {
e.printStackTrace();
}
}
}
if((char)m_binArray[m_currentIndex + 1] == '-') break;
m_currentIndex = m_currentIndex + 2;
} while(true);
}
private String getDataFieldValue(String dataHeader, String fieldName) {
String token = new String();
String value = new String();
int pos = 0;
int i = 0;
int start = 0;
int end = 0;
token = String.valueOf((new StringBuffer(String.valueOf(fieldName))).append("=").append('"'));
pos = dataHeader.indexOf(token);
if(pos > 0) {
i = pos + token.length();
start = i;
token = "\"";
end = dataHeader.indexOf(token, i);
if(start > 0 && end > 0) value = dataHeader.substring(start, end);
} return value;
}
private String getDataHeader() {
int start = m_currentIndex;
int end = 0;
int len = 0;
boolean found = false;
while(!found)
if(m_binArray[m_currentIndex] == 13 && m_binArray[m_currentIndex + 2] == 13) {
found = true;
end = m_currentIndex - 1;
m_currentIndex = m_currentIndex + 2;
} else {
m_currentIndex++;
}
String dataHeader = new String(m_binArray, start, (end - start) + 1);
return dataHeader;
}
private void getDataSection() {
boolean found = false;
String dataHeader = new String();
int searchPos = m_currentIndex;
int keyPos = 0;
int boundaryLen = m_boundary.length();
m_startData = m_currentIndex;
m_endData = 0;
do {
if(searchPos >= m_totalBytes) break;
if(m_binArray[searchPos] == (byte)m_boundary.charAt(keyPos)) {
if(keyPos == boundaryLen - 1) {
m_endData = ((searchPos - boundaryLen) + 1) - 3;
break;
}
searchPos++;
keyPos++;
} else {
searchPos++;
keyPos = 0;
}
} while(true);
m_currentIndex = m_endData + boundaryLen + 3;
}
private String getFileExt(String fileName) {
String value = new String();
int start = 0;
int end = 0;
if(fileName == null) return null;
start = fileName.lastIndexOf(46) + 1;
end = fileName.length();
value = fileName.substring(start, end);
if(fileName.lastIndexOf(46) > 0) return value;
else return "";
}
private String getContentType(String dataHeader) {
String token = new String();
String value = new String();
int start = 0;
int end = 0;
token = "Content-Type:";
start = dataHeader.indexOf(token) + token.length();
if(start != -1) {
end = dataHeader.length();
value = dataHeader.substring(start, end);
}
return value;
}
private String getTypeMIME(String ContentType) {
String value = new String();
int pos = 0;
pos = ContentType.indexOf("/");
if(pos != -1) return ContentType.substring(1, pos);
else return ContentType;
}
private String getSubTypeMIME(String ContentType) {
String value = new String();
int start = 0;
int end = 0;
start = ContentType.indexOf("/") + 1;
if(start != -1) {
end = ContentType.length();
return ContentType.substring(start, end);
} else {
return ContentType;
}
}
}
gnod 2003-02-17
  • 打赏
  • 举报
回复
顺便问一下,我在编译底下的java上传文件时,出现底下的错误,刚刚学jsp还请高手指点

package javax.servlet does not exist
import javax.servlet.*;



yeslebk 2003-02-17
  • 打赏
  • 举报
回复
这是smartupload上的例子,代码如下:

<%@ page language="java" import="com.jspsmart.upload.*"%>
<jsp:useBean id="mySmartUpload" scope="page" class="com.jspsmart.upload.SmartUpload" />

<HTML>
<BODY BGCOLOR="white">


<%

// Variables
int count=0;

// Initialization
mySmartUpload.initialize(pageContext);

// Upload
mySmartUpload.upload();

// Select each file
for (int i=0;i<mySmartUpload.getFiles().getCount();i++){

// Retreive the current file
com.jspsmart.upload.File myFile = mySmartUpload.getFiles().getFile(i);
//com.jspsmart.upload.Request myRequest = mySmartUpload.getRequest();
// Save it only if this file exists
out.println("Request = " + request.getParameter("temp")+ "<BR>");
if (!myFile.isMissing()) {

// Save the files with its original names in a virtual path of the web server

// myFile.saveAs("/upload/" + myFile.getFileName(), mySmartUpload.SAVE_VIRTUAL);

// sample with a physical path
// myFile.saveAs("c:\\temp\\" + myFile.getFileName(), mySmartUpload.SAVE_PHYSICAL);

// Display the properties of the current file

out.println("FieldName = " + myFile.getFieldName() + "<BR>");
out.println("Size = " + myFile.getSize() + "<BR>");
out.println("FileName = " + myFile.getFileName() + "<BR>");
out.println("FileExt = " + myFile.getFileExt() + "<BR>");
out.println("FilePathName = " + myFile.getFilePathName() + "<BR>");
out.println("ContentType = " + myFile.getContentType() + "<BR>");
out.println("ContentDisp = " + myFile.getContentDisp() + "<BR>");
out.println("TypeMIME = " + myFile.getTypeMIME() + "<BR>");
out.println("SubTypeMIME = " + myFile.getSubTypeMIME() + "<BR>");
myFile.saveAs("/home/web/www/test01/" + myFile.getFileName());
count ++;

}

}

// Display the number of files which could be uploaded
out.println("<BR>" + mySmartUpload.getFiles().getCount() + " files could be uploaded.<BR>");

// Display the number of files uploaded
out.println(count + " file(s) uploaded.");


%>
</BODY>
</HTML>
leonzhao 2003-02-17
  • 打赏
  • 举报
回复
你的代码!

81,122

社区成员

发帖
与我相关
我的任务
社区描述
Java Web 开发
社区管理员
  • Web 开发社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧