3个前端框架搭建的环境,突然间报错“WebSocket is closed before the connection is established. ” ,程序无法运行,websocket连接失败。这问题只在google chrome浏览器里才产生,而在火狐里确没有这问题。
原因是在web.xml里我为了解决中文问题添加了
<filter>
<filter-name>encodingFilter</filter-name>
<filter-class>org.springframework.web.filter.CharacterEncodingFilter</filter-class>
<span style="color:#FF0000;"><async-supported>true</async-supported></span>
<init-param>
<param-name>encoding</param-name>
<param-value>UTF-8</param-value>
</init-param>
</filter>
<filter-mapping>
<filter-name>encodingFilter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
红色部分是我没有添加的。后来发现,如果添加了就不会报上面的错误了。希望对大家有帮助。