| Author |
Uploading a file Error...?!
|
Zein Nunna
Ranch Hand
Joined: Mar 31, 2005
Posts: 245
|
|
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
|
 |
Paul Sturrock
Bartender
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? Regards Zein
|
 |
Ganesh Gowtham
Ranch Hand
Joined: Mar 30, 2005
Posts: 223
|
|
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
|
Thanks, Ganesh Gowtham
http://ganesh.gowtham.googlepages.com
|
 |
 |
|
|
subject: Uploading a file Error...?!
|
|
|