• 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

Uploading a file Error...?!

 
Ranch Hand
Posts: 245
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Guys,

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
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>
</form>

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(
baseDir,
"Paper",
username,
paperID);


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

// 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) iter.next();
fileName = item.getName();

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

item.write(uploadedFile);
response.sendRedirect("http://www.google.co.uk");
return;
}
} catch (Exception e1) {
System.out.println("Error in writing upload file");
e1.printStackTrace();
}

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

} else
response.sendRedirect("http://www.bbc.co.uk/news");
}

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
Zein
 
Bartender
Posts: 10336
Hibernate Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Zein Nunna
Ranch Hand
Posts: 245
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The error does seem to have been thrown by the servlet container (JRun4).

Which directory do I find the logs?

Regards
Zein
 
Ranch Hand
Posts: 225
IBM DB2 Eclipse IDE Spring
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi nuna....

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

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
 
The harder I work, the luckier I get. -Sam Goldwyn So tiny. - this ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic