我使用tomcat 7.0.77,spring,现在sockjs无法打开信息。 的web.xml
<servlet>
<servlet-name>mvc-dispatcher</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<load-on-startup>1</load-on-startup>
<async-supported>true</async-supported>
</servlet>
<servlet-mapping>
<servlet-name>mvc-dispatcher</servlet-name>
<url-pattern>/cmd/*</url-pattern>
<url-pattern>/webSocketServer</url-pattern>
<url-pattern>/sockjs/webSocketServer/*</url-pattern>
<url-pattern>/sockjs/webSocketServer/info</url-pattern>
<url-pattern>/webSocketServerLogout</url-pattern>
<url-pattern>/webSocketServerSpAlarm</url-pattern>
的java
public class WebSocketConfig extends WebMvcConfigurerAdapter implements WebSocketConfigurer {
@Override
public void registerWebSocketHandlers(WebSocketHandlerRegistry registry) {
// registry.addHandler(systemWebSocketHandler(),"/webSocketServer").addInterceptors(new WebSocketHandshakeInterceptor());
registry.addHandler(systemWebSocketHandler(), "/sockjsWebSocketServer").addInterceptors(new WebSocketHandshakeInterceptor())
.withSockJS();
catalina.out中 信息:映射的URL路径[/ sockjs / webSocketServer / **]到[class org.springframework.web.socket.sockjs.support.SockJsHttpRequestHandler]类型的处理程序 2017年7月17日下午1:01:46 org.springframework.web.servlet.handler.SimpleUrlHandlerMapping registerHandler
HTML
websocket = new SockJS("http://"+local+"/sockjs/webSocketServer");
当我将/ sockjs / webSocketServer / info添加到web.xml中时,首先无法打开/ sockjs / webSocketServer / info,报告 http://172.24.170.178/sockjs/webSocketServer/093/vl3vnd0p/websocket 404错误
感谢
答案 0 :(得分:0)
将servlet-mapping / sockjs / *添加到web.xml 并将html更改为 websocket = new SockJS(&#34; http://&#34; + local +&#34; / sockjs / sockjsWebSocketServer&#34;);
好的,现在好了。 因为对于sockjs,在webConfig中java map url不能直接把它放到web.xml中。 需要添加前缀sockjs(示例)。