在尝试使用 apache commons将文件上传到我的项目文件夹图像时,生成了以下异常:
我正在从 google appengine 的日志查看器中复制这些日志。
2012-08-04 17:52:38.238 /UploadImagesToAisle 500 4381ms 0kb Mozilla/5.0 (X11;
Linux i686; rv:13.0) Gecko/20100101 Firefox/13.0
106.200.242.109 - - [04/Aug/2012:05:22:38 -0700] "POST /UploadImagesToAisle
HTTP/1.1" 500 0 "http://programworks.appspot.com/ValidateCredentials"
"Mozilla/5.0 (X11; Linux i686; rv:13.0) Gecko/20100101 Firefox/13.0"
"programworks.appspot.com" ms=4382 cpu_ms=1773 api_cpu_ms=0 cpm_usd=0.066922
loading_request=1 instance=00c61b117ce6b4d0249c878697d13e1a0a649c
W 2012-08-04 17:52:38.178
Error for /UploadImagesToAisle
java.lang.NoClassDefFoundError: java.rmi.server.UID is a restricted class. Please see the Google App Engine developer's guide for more details.
at com.google.apphosting.runtime.security.shared.stub.java.rmi.server.UID.<clinit>(UID.java)
at org.apache.commons.fileupload.disk.DiskFileItem.<clinit>(DiskFileItem.java:109)
at org.apache.commons.fileupload.disk.DiskFileItemFactory.createItem(DiskFileItemFactory.java:199)
at org.apache.commons.fileupload.FileUploadBase.parseRequest(FileUploadBase.java:361)
at org.apache.commons.fileupload.servlet.ServletFileUpload.parseRequest(ServletFileUpload.java:126)
at Servlets.UploadImagesToAisle.doPost(UploadImagesToAisle.java:49)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:637)
........
我正在尝试在使用 google appengine 作为服务器时上传文件,并且正在将上传的文件复制到我的项目目录中。即在web-pages下的目录中。
这是我用来上传文件的servlet:
@Override
protected void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
String path = request.getParameter("Data");
PrintWriter writer = response.getWriter();
try {
boolean isMultipart = ServletFileUpload.isMultipartContent(request);
if( !isMultipart ) {
writer.println("File cannot be uploaded !");
} else {
DiskFileItemFactory diskFileItem = new DiskFileItemFactory();
ServletFileUpload fileUpload = new ServletFileUpload(diskFileItem);
List list = null;
try {
list = fileUpload.parseRequest(request);
}catch(Exception exc) {
writer.println(exc);
}
Iterator iterator = list.iterator();
while(iterator.hasNext()) {
FileItem fileItem = (FileItem)iterator.next();
if(fileItem.isFormField()) {
// Process regular form field (input type="text|radio|checkbox|etc", select, etc).
} else {
// Process form file field (input type="file").
String fieldName = fileItem.getFieldName();
String fileName = FilenameUtils.getName(fileItem.getName());
File file = new File("images/",fileName);
fileItem.write(file);
}
}
}
}catch(Exception exc) {
writer.println(exc);
}
}
html片段
<form method="post" enctype="multipart/form-data" action="../../UploadImagesToAisle">
<input type="file" name="Data"/>
<input type="submit" value="upload"/>
</form>
我要上传文件的项目内的图像目录: