FileUpload 1.2 + NetBeans5.5 + Servlet

Pessoal,

Desculpa, mas mesmo pesquisando não consegui encontrar aonde está o erro abaixo. Se puderem me ajudar agradeço muito. Estou usando Netbeans 5.5 com TomCat embutido.

uploadServlet.java

/*

  • uploadServlet.java
  • Created on 3 de Maio de 2007, 07:53
    */

package beans;

/**
*

  • @author F1390
    */

import java.io.;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Iterator;
import java.util.List;
import java.util.StringTokenizer;
import java.net.
;
import javax.servlet.;
import javax.servlet.http.
;
import org.apache.commons.fileupload.FileItem;
import org.apache.commons.fileupload.FileItemFactory;
import org.apache.commons.fileupload.FileUploadBase;
import org.apache.commons.fileupload.disk.DiskFileItemFactory;
import org.apache.commons.fileupload.servlet.ServletFileUpload;

public class uploadServlet extends HttpServlet {

private String msg = null;
private String path=“C:\temp\”;
private String filename = null;
public String getMsg() {
return msg;
}

 public void setMsg(String msg) {
     this.msg = msg;
 }

 public String getPath() {
     return path;
 }

 public void setFilename(String filename) {
     this.filename = filename;
 }

 public String getFilename() {
     return filename;
 }


 protected void processRequest(HttpServletRequest request, HttpServletResponse response)
 throws ServletException, IOException {
     //String idProjeto = request.getInputStream("idProjeto");
       
     int MB = 1024 * 1024;
     boolean isMultipart = ServletFileUpload.isMultipartContent(request);       
     FileItemFactory factory = new DiskFileItemFactory();   
     ServletFileUpload upload = new ServletFileUpload(factory);
     
     try{
         upload.setSizeMax(MB);

         List items = upload.parseRequest(request);
         Iterator iter = items.iterator();

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

             if(!item.isFormField()){
                 setFilename(item.getName());
                 if((getFilename()!=null)&&(!getFilename().equals(""))){
                     if(isPermission(getFilename())){
                         setFilename((new File(getFilename())).getName());
                         String[] nomeSplit = getFilename().split("\\.");
                         setFilename(nomeData()+"."+nomeSplit[1]);
                         item.write(new File(getPath() +getFilename()));
                         setMsg(getFilename()+" - Arquivo enviado com sucesso!");
                     }
                     else{
                         setMsg("Arquivo não permitido para upload");
                         imprimir(request, response);
                     }
                 }
             }
         }
     }
     catch(FileUploadBase.SizeLimitExceededException slee){
         slee.printStackTrace();
         setMsg("Tamanho exedido"); 
         setFilename("");
         imprimir(request, response);
     }
     catch(Exception e){
         e.printStackTrace();     
     }

// response.sendRedirect(“index.jsp”);
response.setContentType(“text/html;charset=UTF-8”);
PrintWriter out = response.getWriter();

     out.println("<html>");
     out.println("<head>");
     out.println("<title>Servlet uploadServlet</title>");
     out.println("</head>");
     out.println("<body>");
     out.println("File Uploaded Proprieties <br><rh>");
     out.println("nome do arquivo: <strong>"+ getFilename() +"</strong><br>");
     out.println("path do arquivo: <strong>"+ getPath() +"</strong><br>");

// out.println(“idProjeto: “+ idProjeto +”
”);
out.println(“Erro de tamanho: “+ getMsg() +””);
out.println("");
out.println("");

     out.close();
     

     
 }
 private boolean isPermission(String fileName){
     String lowerCaseName = fileName.toLowerCase();
     StringTokenizer st = new StringTokenizer("jpg,JGP,jpeg,JPEG,gif,GIF,doc,DOC,txt,TXT"," ,");
     while(st.hasMoreTokens()){
         if(lowerCaseName.endsWith("."+st.nextToken())){
            return true; 
         }
     }
     return false;
 }
 
 private void imprimir (HttpServletRequest request, HttpServletResponse response)
     throws ServletException, IOException {
     
     response.setContentType("text/html;charset=UTF-8");
     PrintWriter out = response.getWriter();
     
     out.println("<html>");
     out.println("<head>");
     out.println("<title>Servlet uploadServlet</title>");
     out.println("</head>");
     out.println("<body>");
     out.println("File Uploaded errors <br><rh>");
     out.println("Erro: <strong>"+ getMsg() +"</strong>");
     out.println("</body>");
     out.println("</html>");

     out.close();
 }
 
 private String nomeData(){
     Date hoje = new Date(); 
     System.out.println ("A data de hoje é: "+ hoje);
     SimpleDateFormat formatter = new SimpleDateFormat("yyMMddhhmmss"); 
     String nome = formatter.format(hoje);
     return nome;
 }
 // <editor-fold defaultstate="collapsed" desc="HttpServlet methods. Click on the + sign on the left to edit the code.">
 /** Handles the HTTP <code>GET</code> method.
  * @param request servlet request
  * @param response servlet response
  */
 protected void doGet(HttpServletRequest request, HttpServletResponse response)
 throws ServletException, IOException {
     processRequest(request, response);
 }
 
 /** Handles the HTTP <code>POST</code> method.
  * @param request servlet request
  * @param response servlet response
  */
 protected void doPost(HttpServletRequest request, HttpServletResponse response)
 throws ServletException, IOException {
     processRequest(request, response);
 }
 
 /** Returns a short description of the servlet.
  */
 public String getServletInfo() {
     return "Short description";
 }
 // </editor-fold>

}


index.jsp

<%@page contentType=“text/html”%>
<%@page pageEncoding=“UTF-8”%>

JSP Page
 <h1>JSP Page</h1>
 
 <form name="form1" method="post" action="uploadServlet" enctype="multipart/form-data">
     Arquivo:<input type="file" name="fileItem" value="" width="30" />
     Projeto:<input type="text" name="idProjeto" id="idProjeto" value="33" />
     <input type="submit" value="Send" />
 </form>
 
 </body>

erro

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
org.netbeans.modules.web.monitor.server.MonitorFilter.doFilter(MonitorFilter.java:368)

root cause

java.lang.NoClassDefFoundError: org/apache/commons/io/output/DeferredFileOutputStream
org.apache.commons.fileupload.disk.DiskFileItemFactory.createItem(DiskFileItemFactory.java:191)
org.apache.commons.fileupload.FileUploadBase.parseRequest(FileUploadBase.java:350)
org.apache.commons.fileupload.servlet.ServletFileUpload.parseRequest(ServletFileUpload.java:126)
beans.uploadServlet.processRequest(uploadServlet.java:67)
beans.uploadServlet.doPost(uploadServlet.java:176)
javax.servlet.http.HttpServlet.service(HttpServlet.java:709)
javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
org.netbeans.modules.web.monitor.server.MonitorFilter.doFilter(MonitorFilter.java:368)

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


Obrigado,
Júlio César