1 Replies - 1914 Views - Last Post: 01 February 2010 - 11:55 AM Rate Topic: -----

#1 harrymash2006  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 4
  • Joined: 18-January 10

drag and drop applet

Posted 01 February 2010 - 05:12 AM

i m trying the following code to upload the dragged the contents to server...but i m getting the error like follow:

" Server returned HTTP response code: 500 for URL: http://localhost:808...fileupload1.jsp?
"
please help me to solve this.

//this is my fileupload1.jsp

<%@ page import="java.io.*" %>
<%@ page import="java.net.*" %>
<%@ page import="java.util.*" %>
<%@ page import="org.apache.commons.fileupload.*" %>
<%@ page import="org.apache.commons.fileupload.servlet.*" %>
<%@ page import="org.apache.commons.fileupload.disk.*" %>

<%
boolean isMultipart = ServletFileUpload.isMultipartContent(request);

// check if the http request is a multipart request
// with other words check that the http request can have uploaded files
if (isMultipart) {
String filename;
String appPath=application.getRealPath("/");
out.println(application.getRealPath("/"));
String destFolder = appPath + "data/";

// The base upload directory. In this directory all uploaded files will
// be stored. With the applet param tag 'directory' you can create a
// subdirectory for a user.
// See http://www.javaatwor....html#directory for more
// information about the 'directory' param tag. For a Windows environment
// the base_directory can be e.g. 'c:/temp' for Linux environment '/tmp'.
String base_directory = destFolder;

// Create a factory for disk-based file items
FileItemFactory factory = new DiskFileItemFactory();

// Create a new file upload handler
ServletFileUpload servletFileUpload = new ServletFileUpload(factory);

// Set upload parameters
// See Apache Commons FileUpload for more information
// http://jakarta.apach...load/using.html
servletFileUpload.setSizeMax(100000);

try {

String directory = "";

// Parse the request
List<FileItem> items = servletFileUpload.parseRequest(request);

// Process the uploaded items
Iterator<FileItem> iter = items.iterator();

while (iter.hasNext()) {
FileItem item = (FileItem) iter.next();

// the param tag directory is sent as a request parameter to the server
// check if the upload directory is available


// retrieve the files

// the fileNames are urlencoded
String fileName = URLDecoder.decode(item.getName());

File file = new File(directory, fileName);
file = new File(base_directory, file.getPath());

// retrieve the parent file for creating the directories
File parentFile = file.getParentFile();

if (parentFile != null) {
parentFile.mkdirs();
}

// writes the file to the filesystem
item.write(file);
}
}

catch (Exception e) {
e.printStackTrace();
response.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
}
}

%>

Is This A Good Question/Topic? 0
  • +

Replies To: drag and drop applet

#2 Paul-  Icon User is offline

  • D.I.C Regular
  • member icon

Reputation: 61
  • View blog
  • Posts: 260
  • Joined: 11-December 09

Re: drag and drop applet

Posted 01 February 2010 - 11:55 AM

Try reading the server error log for details on what is causing the problem. The exact location of this file will depend on your system. On my Tomcat, for example, the error log is at /var/log/apache2/error_log.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1