【问题标题】:Jetty Websockets can't connect to serverJetty Websockets 无法连接到服务器
【发布时间】:2013-05-18 14:19:47
【问题描述】:

所以我已经正确设置了一个监听 8080 的码头(基于 Eclipse)服务器。(我放了一点 hello world html 来测试)。所以如果我去

http://localhost:8080/index.html

我的 html 显示出来了。

现在我已经按照本教程使用 Websockets。

https://gist.github.com/manzke/1021982

web.xml 配置如下:

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" version="2.5">
  <display-name>tailor</display-name>
  <servlet>
    <servlet-name>WebSocket</servlet-name>
    <servlet-class>org.sample.websocket.ChatWebSocketServlet</servlet-class>
  </servlet>
  <servlet-mapping>
    <servlet-name>WebSocket</servlet-name>
    <url-pattern>/jetty-test/*</url-pattern>
  </servlet-mapping>
  <welcome-file-list>
    <welcome-file>index.html</welcome-file>
  </welcome-file-list>
</web-app>

要连接到我的 Websocket,我使用以下网址:

ws://localhost:8080/jetty-test/servlet/WebSocket

但是当我点击“连接”时什么也没发生?,连接似乎没有建立..

我错过了什么吗?还是网址不对?

谢谢!

【问题讨论】:

    标签: websocket jetty localhost


    【解决方案1】:

    你的web.xml有错,替换

    <url-pattern>/jetty-test/*</url-pattern>
    

    通过

    <url-pattern>/servlet/*</url-pattern>
    

    【讨论】:

      猜你喜欢
      • 2015-01-04
      • 1970-01-01
      • 2018-05-23
      • 2013-04-20
      • 1970-01-01
      • 1970-01-01
      • 2019-02-03
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多