0
votes
List<?> items =upload.parseRequest(request);

The method parseRequest(HttpServletRequest, int, long, String) in the type DiskFileUpload is not applicable for the arguments (HttpServletRequest)


When i Run as Server...it gives error on console

May 13, 2012 7:47:49 PM org.apache.tomcat.util.digester.Digester startElement SEVERE: Begin event threw error java.lang.NoSuchMethodError: org.apache.tomcat.util.ExceptionUtils.unwrapInvocationTargetException(Ljava/lang/Throwable;)Ljava/lang/Throwable; at org.apache.catalina.core.AprLifecycleListener.init(AprLifecycleListener.java:185) at org.apache.catalina.core.AprLifecycleListener.isAprAvailable(AprLifecycleListener.java:84) at org.apache.catalina.connector.Connector.setProtocol(Connector.java:577) at org.apache.catalina.connector.Connector.(Connector.java:69) at org.apache.catalina.startup.ConnectorCreateRule.begin(ConnectorCreateRule.java:62) at org.apache.tomcat.util.digester.Digester.startElement(Digester.java:1356) at com.sun.org.apache.xerces.internal.parsers.AbstractSAXParser.startElement(AbstractSAXParser.java:506) at com.sun.org.apache.xerces.internal.parsers.AbstractXMLDocumentParser.emptyElement(AbstractXMLDocumentParser.java:182) at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl.scanStartElement(XMLDocumentFragmentScannerImpl.java:1302) at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl$FragmentContentDriver.next(XMLDocumentFragmentScannerImpl.java:2715) at com.sun.org.apache.xerces.internal.impl.XMLDocumentScannerImpl.next(XMLDocumentScannerImpl.java:607) at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl.scanDocument(XMLDocumentFragmentScannerImpl.java:488) at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(XML11Configuration.java:835) at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(XML11Configuration.java:764) at com.sun.org.apache.xerces.internal.parsers.XMLParser.parse(XMLParser.java:123) at com.sun.org.apache.xerces.internal.parsers.AbstractSAXParser.parse(AbstractSAXParser.java:1210) at com.sun.org.apache.xerces.internal.jaxp.SAXParserImpl$JAXPSAXParser.parse(SAXParserImpl.java:568) at org.apache.tomcat.util.digester.Digester.parse(Digester.java:1642) at org.apache.catalina.startup.Catalina.load(Catalina.java:576) at org.apache.catalina.startup.Catalina.load(Catalina.java:619) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:601) at org.apache.catalina.startup.Bootstrap.load(Bootstrap.java:281) at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:449)

java.lang.NoSuchMethodError: org.apache.tomcat.util.ExceptionUtils.unwrapInvocationTargetException(Ljava/lang/Throwable;)Ljava/lang/Throwable; at org.apache.catalina.core.AprLifecycleListener.init(AprLifecycleListener.java:185) at org.apache.catalina.core.AprLifecycleListener.isAprAvailable(AprLifecycleListener.java:84) at org.apache.catalina.connector.Connector.setProtocol(Connector.java:577) at org.apache.catalina.connector.Connector.(Connector.java:69) at org.apache.catalina.startup.ConnectorCreateRule.begin(ConnectorCreateRule.java:62) at org.apache.tomcat.util.digester.Digester.startElement(Digester.java:1356) at com.sun.org.apache.xerces.internal.parsers.AbstractSAXParser.startElement(AbstractSAXParser.java:506) at com.sun.org.apache.xerces.internal.parsers.AbstractXMLDocumentParser.emptyElement(AbstractXMLDocumentParser.java:182) at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl.scanStartElement(XMLDocumentFragmentScannerImpl.java:1302) at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl$FragmentContentDriver.next(XMLDocumentFragmentScannerImpl.java:2715) at com.sun.org.apache.xerces.internal.impl.XMLDocumentScannerImpl.next(XMLDocumentScannerImpl.java:607) at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl.scanDocument(XMLDocumentFragmentScannerImpl.java:488) at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(XML11Configuration.java:835) at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(XML11Configuration.java:764) at com.sun.org.apache.xerces.internal.parsers.XMLParser.parse(XMLParser.java:123) at com.sun.org.apache.xerces.internal.parsers.AbstractSAXParser.parse(AbstractSAXParser.java:1210) at com.sun.org.apache.xerces.internal.jaxp.SAXParserImpl$JAXPSAXParser.parse(SAXParserImpl.java:568) at org.apache.tomcat.util.digester.Digester.parse(Digester.java:1642) at org.apache.catalina.startup.Catalina.load(Catalina.java:576) at org.apache.catalina.startup.Catalina.load(Catalina.java:619) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:601) at org.apache.catalina.startup.Bootstrap.load(Bootstrap.java:281) at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:449)


This is my code in this code List<?> items =upload.parseRequest(request); Got error as The method parseRequest(HttpServletRequest, int, long, String) in the type DiskFileUpload is not applicable for the arguments (HttpServletRequest)

package br.com.ecommerce.servlet;

import java.io.File;
import java.io.IOException;
import java.util.Iterator;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.tomcat.util.http.fileupload.disk.*;
import org.apache.tomcat.util.http.fileupload.servlet.*;
import org.apache.tomcat.util.http.fileupload.util.*;


import org.apache.tomcat.util.http.fileupload.DiskFileUpload;
import org.apache.tomcat.util.http.fileupload.FileItem;
import org.apache.tomcat.util.http.fileupload.FileUpload;
import org.apache.tomcat.util.http.fileupload.FileUploadException;
import org.apache.tomcat.util.http.fileupload.RequestContext;

import br.com.ecommerce.bean.Produtos;
import br.com.ecommerce.controller.ExceptionController;
import br.com.ecommerce.dao.CategoriasDao;
import br.com.ecommerce.dao.ProdutosDao;
 class UploadServlet extends HttpServlet {

    private static final long serialVersionUID = 1L;

    public UploadServlet() {
        super();

    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

    }

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

        response.setContentType("text/plain");
        Produtos produto = new Produtos();

        String caminhoTemp = new String("C:\\Users\\vaio\\workspace\\ecommerce\\WebContent\\images\\upload");
        String pasta = new String("C:\\Users\\vaio\\workspace\\ecommerce\\WebContent\\images\\upload");
        String caminho = new String("images\\upload\\");

        if (ServletFileUpload.isMultipartContent( request)){

            DiskFileUpload upload = new DiskFileUpload();

            upload.setRepositoryPath(caminhoTemp);

            try{
    List<?> items =upload.parseRequest(request);//In this line i got error..why?..Pls help

                Iterator<?> iter = items.iterator();

                while (iter.hasNext()) {

                    FileItem item = (FileItem) iter.next();

                    if(item.isFormField()){  

                        if(item.getFieldName().equals("nome")){  
                            produto.setProdNome(item.getString().toUpperCase());
                        }

                        else if (item.getFieldName().equals("categoria")){
                            produto.setCategorias(new CategoriasDao().findByPK(Integer.valueOf(item.getString())));
                        }

                        else if (item.getFieldName().equals("preco")){
                            produto.setPreco(Double.valueOf(item.getString()));

                            Double preco = 0d;
                            preco = Double.valueOf(item.getString());
                            preco += 10.00;
                            System.out.println(preco);
                        }

                        else if (item.getFieldName().equals("descp")){
                            produto.setDescPeq(item.getString());
                        }

                        else if (item.getFieldName().equals("descg")){
                            produto.setDescGd(item.getString());
                        }

                        else if (item.getFieldName().equals("espec")){
                            produto.setEspecificacoes(item.getString());
                        }

                        else if (item.getFieldName().equals("itens")){
                            produto.setItensInclusos(item.getString());
                        }

                        produto.setPromocao(0);
                        produto.setDestaque(0);
                }   

                if (!item.isFormField()) {

                    String nome = item.getName().toString();
                    String nomeArquivo = nome.substring(nome.lastIndexOf("\\")+1);

                    File arquivo = new File(pasta + "\\" + nomeArquivo);

                    produto.setImagem(caminho + nomeArquivo);

                    item.write(arquivo);

                }
            }





            }catch(FileUploadException e){

                e.printStackTrace();
            } catch (Exception e) {
                e.printStackTrace();
            }
            }

            try {
                new ProdutosDao().insert(produto);

            } catch (ExceptionController e) {
                e.printStackTrace();
            }

        response.sendRedirect("/ecommerce/admin/gerenciarProdutos.jsp");

    }

}
enter code here
1

1 Answers

0
votes

Are you trying to use the DiskFileUpload class from Commons FileUpload? If so, make sure your class is importing org.apache.commons.fileupload.DiskFileUpload, and not some other class called DiskFileUpload.