• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Detailed description for william : regarding JAR files

 
Ranch Hand
Posts: 102
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi
Actually i have downloaded a JAR file.
I have also placed the jar file in jspbook/WEB-INF/lib/ folder .
I am trying file upload through a HTML file which has following code. actually i am accessing servlet FileUploadCommons though this HTML file and using an API for file upload present in that JAR file.

<html>
<head>
<title>Example HTML Form</title>
</head>
<body>
<p>Select a file to upload or <a href="/jspbook/files/">browse
currently uploaded files.</a></p>
<form action="http://127.0.0.1/jspbook/FileUploadCommons"
method="post" enctype="multipart/form-data">
File: <input type="file" name="file"><br>
<input value="Upload File" type="submit">
</form>
</body>
</html>



The source code for servlet FileUploadCommons is as follows ::::


package com.jspbook;

import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;
import org.apache.commons.fileupload.*;
import java.util.*;

public class FileUploadCommons extends HttpServlet {
public void doPost(HttpServletRequest request,
HttpServletResponse response)
throws IOException, ServletException {

response.setContentType("text/html");
PrintWriter out = response.getWriter();

out.println("<html>");
out.print("File upload success. <a href=\"/jspbook/files/");
out.print("\">Click here to browse through all uploaded ");
out.println("files.</a><br>");

ServletContext sc = getServletContext();
String path = sc.getRealPath("/files");
org.apache.commons.fileupload.FileUpload fu = new
org.apache.commons.fileupload.FileUpload();
fu.setSizeMax(-1);
fu.setRepositoryPath(path);
try {
List l = fu.parseRequest(request);
Iterator i = l.iterator();
while (i.hasNext()) {
FileItem fi = (FileItem)i.next();
// trim out full path info if it is included
String filename = fi.getName();
int slash = filename.lastIndexOf("\\");
if (slash != -1) {
filename = filename.substring(slash + 1);
}
// write the file to the 'files' directory
fi.write(path+"/"+filename);
}
}
catch (Exception e) {
throw new ServletException(e);
}

out.println("</html>");
}
public void doGet(HttpServletRequest request,
HttpServletResponse response)
throws IOException, ServletException {
doPost(request, response);
}
}



Also i am using Tomcat 5 as the web server.


But when i try to upload the file by running the HTML file i am getting the following ERROR MESSAGE :


HTTP Status 500 -

--------------------------------------------------------------------------------

type Exception report

message

description The server encountered an internal error () that prevented it from fulfilling this request.

exception

javax.servlet.ServletException: Servlet execution threw an exception


root cause

java.lang.NoSuchMethodError: org.apache.commons.fileupload.FileUpload.setSizeMax(I)V
com.jspbook.FileUploadCommons.doPost(Unknown Source)
javax.servlet.http.HttpServlet.service(HttpServlet.java:709)
javax.servlet.http.HttpServlet.service(HttpServlet.java:802)


note The full stack trace of the root cause is available in the Apache Tomcat/5.0.28 logs.


--------------------------------------------------------------------------------

Apache Tomcat/5.0.28




Please tell me what to do?
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic