List<?> items =upload.parseRequest(request);
DiskFileUpload 型のメソッド parseRequest(HttpServletRequest, int, long, String) は、引数 (HttpServletRequest) には適用されません。
サーバーとして実行すると...コンソールでエラーが発生します
2012 年 5 月 13 日 7:47:49 PM org.apache.tomcat.util.digester.Digester startElement SEVERE: Begin イベントがエラー java.lang.NoSuchMethodError をスローしました: org.apache.tomcat.util.ExceptionUtils.unwrapInvocationTargetException(Ljava/lang/スロー可能;)Ljava/lang/Throwable; org.apache.catalina.core.AprLifecycleListener.init(AprLifecycleListener.java:185) で org.apache.catalina.core.AprLifecycleListener.isAprAvailable(AprLifecycleListener.java:84) で org.apache.catalina.connector.Connector.setProtocol (Connector.java:577) org.apache.catalina.connector.Connector で (Connector.java:69) org.apache.catalina.startup.ConnectorCreateRule.begin(ConnectorCreateRule.java:62) で org.apache.tomcat .util.digester.Digester.startElement(Digester.java:1356) com.sun.org.apache.xerces.internal.parsers.AbstractSAXParser.
java.lang.NoSuchMethodError: org.apache.tomcat.util.ExceptionUtils.unwrapInvocationTargetException(Ljava/lang/Throwable;)Ljava/lang/Throwable; org.apache.catalina.core.AprLifecycleListener.init(AprLifecycleListener.java:185) で org.apache.catalina.core.AprLifecycleListener.isAprAvailable(AprLifecycleListener.java:84) で org.apache.catalina.connector.Connector.setProtocol (Connector.java:577) org.apache.catalina.connector.Connector で (Connector.java:69) org.apache.catalina.startup.ConnectorCreateRule.begin(ConnectorCreateRule.java:62) で org.apache.tomcat .util.digester.Digester.startElement(Digester.java:1356) com.sun.org.apache.xerces.internal.parsers.AbstractSAXParser.startElement(AbstractSAXParser.java:506) com.sun.org.apache.xerces で.internal.parsers.AbstractXMLDocumentParser.
これは、このコードの私のコードです
List<?> items =upload.parseRequest(request);
タイプ DiskFileUpload のメソッド parseRequest(HttpServletRequest, int, long, String) が引数 (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