-2

I am creating a web app and keep coming across this error

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)

here is my 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>

The Servlet itself (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
}

And the post to the servlet(JS)

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

I am running this on eclipse which I know has some issues when running a tomcat server but I have already cleaned and built the project before asking this question

I am positive it is something trivial that I am just overlooking but any help is appreciated

Georgrio
  • 91
  • 2
  • 14

1 Answers1

-1

The servlet-class tag value in the web.xml is not pointing to the correct Servlet class.

I noticed you are using Jersey REST API implementation to expose your REST service, so you have two options; either use the Jersey Servlet to handle your requests instead of the your own resource class (GeneSpotAnalysis) or change your @Path annotation to @ApplicationPath.

Using the first and more traditional option you can change the web.xml in this line:

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

for this:

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

You can check more details on this page https://jersey.java.net/documentation/latest/deployment.html#deployment.servlet.3

brunocrt
  • 720
  • 9
  • 11