求救!maven 运行tomcat7:run 之后跳转servlet出现SearchImageServlet is not a Servlet cannot be cast to javax.serv

HTTP Status 500 - Class com.ai.deepsearch.SearchImageServlet is not a Servlet


type Exception report

message Class com.ai.deepsearch.SearchImageServlet is not a Servlet

description The server encountered an internal error that prevented it from fulfilling this request.

exception

javax.servlet.ServletException: Class com.ai.deepsearch.SearchImageServlet is not a Servlet
	org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:472)
	org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:99)
	org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:936)
	org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:407)
	org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1004)
	org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:589)
	org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:312)
	java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
	java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
	java.lang.Thread.run(Thread.java:748)

 

root cause

java.lang.ClassCastException: com.ai.deepsearch.SearchImageServlet cannot be cast to javax.servlet.Servlet
	org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:472)
	org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:99)
	org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:936)
	org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:407)
	org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1004)
	org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:589)
	org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:312)
	java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
	java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
	java.lang.Thread.run(Thread.java:748)

 

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

 

 

 

 

 

 

 

下面是我的servlet

package com.ai.deepsearch;

import org.apache.commons.fileupload.FileItem;
import org.apache.commons.fileupload.FileUploadException;
import org.apache.commons.fileupload.disk.DiskFileItemFactory;
import org.apache.commons.fileupload.servlet.ServletFileUpload;
import org.datavec.image.loader.NativeImageLoader;
import org.nd4j.linalg.api.ndarray.INDArray;
import org.nd4j.linalg.dataset.api.preprocessor.DataNormalization;
import org.nd4j.linalg.dataset.api.preprocessor.VGG16ImagePreProcessor;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.File;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.List;
import java.util.Map;
import java.util.Set;

/**
 *  搜索请求Servlet
 */
@WebServlet(value = "/search")
public class SearchImageServlet extends HttpServlet {

    @Override
    public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        System.out.println("SearchImageServlet servlet handling post");
        try {
            DiskFileItemFactory factory = new DiskFileItemFactory();
            File f=new File("E:\\storetest");
            factory.setRepository(f);
            ServletFileUpload fileUpload = new ServletFileUpload(factory);
            String uploadDir = request.getSession().getServletContext().getRealPath("/upload_imgs");
            List<FileItem> fileItems = fileUpload.parseRequest(request);
            System.out.println("file items size:"+fileItems.size());
            for (FileItem item : fileItems) {
                if(!item.isFormField()) {
                    String fileName=item.getName();
                    if(fileName.lastIndexOf("\\")>=0) {
                        fileName=fileName.substring(fileName.lastIndexOf("\\"));
                    } else {
                        fileName=fileName.substring(fileName.lastIndexOf("\\")+1);
                    }
                    File uploadFile=new File(uploadDir+"/"+fileName);
                    if(!uploadFile.exists()) {
                        uploadFile.getParentFile().mkdirs();
                    }
                    uploadFile.createNewFile();
                    item.write(uploadFile);
                    item.delete();

                    NativeImageLoader loader=new NativeImageLoader(224,224,3);
                    INDArray imageArray=loader.asMatrix(uploadFile);
                    DataNormalization scaler=new VGG16ImagePreProcessor();
                    scaler.transform(imageArray);

                    Map<String,INDArray> map=WebEngineInit.vgg16Model.feedForward(imageArray,false);
                    INDArray feature=map.get("fc2");

                    String imagesDb = request.getSession().getServletContext().getRealPath("/WEB-INF/image.db");

                    Set<String> result=SearchSimilarImgs.search(true,imagesDb,fileName,feature);

                    response.setContentType("text/html;charset=utf-8");
                    PrintWriter writer=response.getWriter();
                    writer.println("<html>");
                    writer.println("<head>");
                    writer.println("<title>查询结果</title>");
                    writer.println("<link rel=\"stylesheet\" type=\"text/css\" href=\"./css/style.css\" />");
                    writer.println("</head>");
                    writer.println("<body>");
                    writer.println("<div class=\"search\">");
                    writer.println("<div class=\"back_btn\"><a href=\"http://localhost:8080/imgsearch/\">回主页</a></div>");
                    writer.println("<div class=\"title_search\"><span>查询图像</span></div>");
                    writer.println("</div>");
                    writer.println("<div>");
                    writer.println("<div class=\"search_img\"><img src=\"./upload_imgs/"+fileName+"\"></div>");
                    writer.println("</div>");
                    writer.println("<div class=\"line\"></div>");
                    writer.println("<div class=\"simi\">");
                    writer.println("<div class=\"title_simi\"><span>相似图像</span></div>");
                    writer.println("</div>");
                    writer.println("<div id=\"result\">");
                    for(String r:result) {
                        writer.println("<div class=\"simi_img\"><img src=\"./image/"+r+"\"></div>");
                        System.out.println(r);
                    }
                    writer.println("</div>");
                    writer.println("</body>");
                    writer.println("</html>");
                    writer.flush();
                    writer.close();
                }
            }
        } catch (FileUploadException e) {
            e.printStackTrace();
        } catch (Exception e) { // item.write(uploadImages)
            e.printStackTrace();
        }
    }
}
  • 0
    点赞
  • 2
    评论
  • 0
    收藏
  • 打赏
    打赏
  • 扫一扫,分享海报

©️2022 CSDN 皮肤主题:大白 设计师:CSDN官方博客 返回首页

打赏作者

ConnyBunny_jz

你的鼓励将是我创作的最大动力

¥2 ¥4 ¥6 ¥10 ¥20
输入1-500的整数
余额支付 (余额:-- )
扫码支付
扫码支付:¥2
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、C币套餐、付费专栏及课程。

余额充值