0
Tomcat 6 (비즈니스 요구 사항)에서 웹 소켓을 사용할 방법이 있습니까?Tomcat 6에서 웹 소켓 사용
내가 javax.websocket.jar를 사용하여 노력했지만 내가 여기
를 동작하지 않습니다 내 코드입니다 :
import java.io.IOException;
import java.nio.ByteBuffer;
import javax.websocket.OnMessage;
import javax.websocket.Session;
import javax.websocket.server.ServerEndpoint;
@ServerEndpoint("/echoAnnotation")
public class EchoAnnotation { @OnMessage
public void echoTextMessage(Session session, String msg, boolean last) {
try {
if (session.isOpen()) {
session.getBasicRemote().sendText(msg, last);
}
} catch (IOException e) {
try {
session.close();
} catch (IOException e1) {
// Ignore
}
}
}
}
그리고 내 web.xml의 :
<?xml version="1.0" encoding="ISO-8859-1"?>
<web-app 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_2_5.xsd"
version="2.5">
<description>
Servlet and JSP Examples.
</description>
<display-name>Servlet and JSP Examples</display-name>
<servlet>
<servlet-name>echoAnnotation</servlet-name>
<servlet-class>EchoAnnotation</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>echoAnnotation</servlet-name>
<url-pattern>/echoAnnotation</url-pattern>
</servlet-mapping>
</web-app>
그러나 웹 소켓 연결을 만들 수 없으며 오류 메시지 Firefox can't establish a connection to the server at ws://192.168.1.101:8080/prototypes/echoAnnotation
이 표시되고 페이지 결과로 직접 이동합니다 HTTP Status 404 - Servlet echoAnnotation is not available
이것이 가능합니까? 내가 도대체 뭘 잘못하고있는 겁니까?
"EchoAnnotation"은 서블릿 유형을 확장하지 않으므로 서블릿으로 인식되지 않습니다. – RealSkeptic
맞아, 샘플을 javax.websocket 용으로 사용했고, 이후 버전의 tomcat 또는 glassfish에서는 지원되지만 Tomcat 6에서는 지원되지 않는 주석을 사용했기 때문입니다. – Malfist