我正在创建一个Web应用程序,并继续遇到此错误
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){
})
我正在运行tomcat服务器时我知道的Eclipse上有一些问题,但是在询问此问题之前,我已经清洁并构建了该项目
我很肯定,我只是忽略了很微不足道的东西
web.xml中的servlet-class-class标签值并未指向正确的servlet类。
我注意到您正在使用Jersey REST API实现来公开您的休息服务,因此您有两个选择。要么使用泽西式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