File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Servlets and the fly likes Uploading a file Error...?! Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "Uploading a file Error...?!" Watch "Uploading a file Error...?!" New topic

Uploading a file Error...?!

Zein Nunna
Ranch Hand

Joined: Mar 31, 2005
Posts: 245

Im using the classes from jakarta to do an upload of a document onto my webserver.

I get the following error

500 org/apache/commons/fileupload/FileUploadBase

Any idea what it can be? Im sure my code is right.

The code for the form is:
<form method="POST" action="./servlet/REJfiles.UploadServlet" enctype="multipart/form-data">
<p><input type="text" name="paperTitle" size="50"></p>
<p><input type="text" name="coAuthors" size="50"></p>
<p><input type="file" name="file" size="50"></p>
<p><font face="Arial">Please make sure you have read the 'instructions
for authors'</font></p>
<input type="submit" value="Submit.." />
<p> </p>
<p> </p>
<p> </p>

and the servelet code is as follow:

public void doPost(
HttpServletRequest request,
HttpServletResponse response)
throws ServletException, IOException {

String username = request.getParameter("user_id");
String paperID = request.getParameter("paper_id");
String baseDir = this.getServletContext().getRealPath("/");

boolean isMultipart = FileUpload.isMultipartContent(request);
String filePath =
new FileUtil().generateFilePath(

if (isMultipart) {
DiskFileUpload upload = new DiskFileUpload();
//Parse the request
try {

// Parse the request
List /* FileItem */
items = upload.parseRequest(request);

Iterator iter = items.iterator();
FileItem item = null;
String fileName = "nothing.txt";
try {
while (iter.hasNext()) {

item = (FileItem);
fileName = item.getName();

File uploadedFile =
new FileUtil().create(filePath, fileName);

} catch (Exception e1) {
System.out.println("Error in writing upload file");

} catch (FileUploadException e) {
System.out.println("Error FileUploadException!");

} else

Can you see a problem anywhere in the code?

I've routed the sendRedirect to different websites to show me if it works or not, dont pay too much attention to that, im going to change it once im done.

Thanks in advance
Paul Sturrock

Joined: Apr 14, 2004
Posts: 10336

Hard to tell with the information you have provided. The only error I can see is the 500 HTTP response message, which means "internal server error". Have you looked at the logs of your servlet container? You should see a more descriptive message.

JavaRanch FAQ HowToAskQuestionsOnJavaRanch
Zein Nunna
Ranch Hand

Joined: Mar 31, 2005
Posts: 245
The error does seem to have been thrown by the servlet container (JRun4).

Which directory do I find the logs?

Ganesh Gowtham
Ranch Hand

Joined: Mar 30, 2005
Posts: 225

Hi nuna....

I have another solution for u....
like just download the jar file in

just make use of it ...
y u re struggling this by trying to get servlet context arel path...
Analysing the req fo rmultipart (MIME )...

Let me get data from java zoom,net

let me know if u didnt get the answer still....

that site has so many instructions how to upload file how to manuplate the code even u can make use of that in struts tooo

Thanks, Ganesh Gowtham
I agree. Here's the link:
subject: Uploading a file Error...?!
It's not a secret anymore!