我正在使用Tomcat Web-Socket服务器。我已成功制作服务器并将其与angularJS Client连接。
现在我正在尝试将类导入到我使用tomcat 7.0.56和web.xml进行servlet映射的原始项目中。
服务器启动正常,但在实例化socket
时出现以下错误的web.xml
<servlet>
<servlet-name>FirstWebSocketCMS</servlet-name>
<servlet-class>com.sss.discovery.FirstWebSocketCMS</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>FirstWebSocketCMS</servlet-name>
<url-pattern>/FirstWebSocketCMS</url-pattern>
</servlet-mapping>
服务器端:
12:20:51,167 INFO [FirstWebSocketCMS] Constructor: FirstWebSocketCMS
Nov 02, 2015 12:20:51 PM org.apache.catalina.core.ApplicationContext log
INFO: Marking servlet FirstWebSocketCMS as unavailable
Nov 02, 2015 12:20:51 PM org.apache.catalina.core.StandardWrapperValve invoke
SEVERE: Allocate exception for servlet FirstWebSocketCMS
java.lang.ClassCastException: com.sss.discovery.FirstWebSocketCMS cannot be cast to javax.servlet.Servlet
at org.apache.catalina.core.StandardWrapper.loadServlet(StandardWrapper.java:1148)
客户端:
WebSocket connection to 'ws://localhost:8080/sr/FirstWebSocketCMS' failed: Error during WebSocket handshake: Unexpected response code: 500
如果删除web.xml内容并将以下注释添加到类中,则一切正常:
@ServerEndpoint(value = "/FirstWebSocketCMS")
public class FirstWebSocketCMS {
}