classcastexception:无法转换为com.sun.jersey.spi.container.servlet.ServletContainer

时间:2017-02-27 17:26:07

标签: java eclipse web-services tomcat servlets

我正在创建一个网络应用并不断遇到此错误

java.lang.ClassCastException: org.uiowa.logsdon.genespot.JobInformation.GeneSpotAnalysis cannot be cast to javax.servlet.Servlet
at org.apache.catalina.core.StandardWrapper.loadServlet(StandardWrapper.java:1050)
at org.apache.catalina.core.StandardWrapper.allocate(StandardWrapper.java:779)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:133)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:108)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:472)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:140)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:79)
at org.apache.catalina.valves.AbstractAccessLogValve.invoke(AbstractAccessLogValve.java:620)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:87)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:349)
at org.apache.coyote.http11.Http11Processor.service(Http11Processor.java:783)
at org.apache.coyote.AbstractProcessorLight.process(AbstractProcessorLight.java:66)
at org.apache.coyote.AbstractProtocol$ConnectionHandler.process(AbstractProtocol.java:789)
at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1455)
at org.apache.tomcat.util.net.SocketProcessorBase.run(SocketProcessorBase.java:49)
at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
at java.lang.Thread.run(Unknown Source)

这是我的web.xml

<?xml version="1.0" encoding="ISO-8859-1"?>
<web-app version="3.0"
  xmlns="http://java.sun.com/xml/ns/javaee"
  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd">


  <display-name>The Gene Spot</display-name>
  <welcome-file-list>
    <welcome-file>jobSubmission 2.html</welcome-file>
  </welcome-file-list>


   <servlet>
      <servlet-name>TheGeneSpot</servlet-name>
      <servlet-class>org.uiowa.logsdon.genespot.JobInformation.GeneSpotAnalysis</servlet-class> 
<init-param>
    <param-name>com.sun.jersey.config.property.packages</param-name>
    <param-value>org.uiowa.logsdon.genespot.JobInformation</param-value>
  </init-param>
   </servlet>

   <!-- Note: All <servlet> elements MUST be grouped together and
         placed IN FRONT of the <servlet-mapping> elements -->

   <servlet-mapping>
      <servlet-name>TheGeneSpot</servlet-name>
      <url-pattern>/analysis/*</url-pattern>
   </servlet-mapping>
</web-app>

Servlet本身(Java)

package org.uiowa.logsdon.genespot.JobInformation;

import java.io.FileNotFoundException;
import java.io.UnsupportedEncodingException;
import java.util.List;

import javax.ws.rs.FormParam;
import javax.ws.rs.POST;
import javax.ws.rs.Path;
@Path("/GeneSpot")
public class GeneSpotAnalysis {
    @POST
    public String Genespot(@FormParam("inputArray[]") List<String> datalist)
            throws UnsupportedEncodingException, FileNotFoundException {
//Code here
}

发布到servlet(JS)

var location =window.location.href+"analysis/GeneSpot"
    var results = $.post(location,{inputArray:inputArray},function(results){
    })

我在eclipse上运行这个,我知道在运行tomcat服务器时有一些问题,但我已经在问这个问题之前已经清理并构建了项目

我很肯定这是一件微不足道的事,我只是在俯视,但感谢任何帮助

1 个答案:

答案 0 :(得分:-1)

web.xml中的servlet-class标记值未指向正确的Servlet类。

我注意到您正在使用Jersey REST API实现来公开您的REST服务,因此您有两个选择;使用Jersey Servlet处理您的请求而不是您自己的资源类(GeneSpotAnalysis)或将@Path注释更改为@ApplicationPath。

使用第一个和更传统的选项,您可以更改 此行中的 web.xml

<servlet-class>org.uiowa.logsdon.JobInformation.GeneSpotAnalysis</servlet-class>

为此:

<servlet-class><servlet-class>com.sun.jersey.spi.container.servlet.ServletContainer</servlet-class> </servlet-class>

您可以在此页面查看更多详细信息 https://jersey.java.net/documentation/latest/deployment.html#deployment.servlet.3