gpt4 book ai didi

tomcat - 由 : javax. websocket.DeploymentException 引起:路径 [websocket] 无效

转载 作者:行者123 更新时间:2023-11-28 21:59:42 27 4
gpt4 key购买 nike

 **16-Jul-2016 15:50:39.774 SEVERE [localhost-startStop-1]  
org.apache.catalina.core.StandardContext.startInternal Error during ServletContainerInitializer processing
javax.servlet.ServletException: javax.websocket.DeploymentException: The path [websocket] is not valid.
at org.apache.tomcat.websocket.server.WsSci.onStartup(WsSci.java:123)
at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5292)
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:147)
at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:725)
at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:701)
at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:717)
at org.apache.catalina.startup.HostConfig.deployDirectory(HostConfig.java:1092)
at org.apache.catalina.startup.HostConfig$DeployDirectory.run(HostConfig.java:1834)
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
at java.util.concurrent.FutureTask.run(FutureTask.java:266)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
at java.lang.Thread.run(Thread.java:745)
Caused by: javax.websocket.DeploymentException: The path [websocket] is not valid.
at org.apache.tomcat.websocket.server.UriTemplate.<init>(UriTemplate.java:48)
at org.apache.tomcat.websocket.server.WsServerContainer.addEndpoint(WsServerContainer.java:200)
at org.apache.tomcat.websocket.server.WsServerContainer.addEndpoint(WsServerContainer.java:279)
at org.apache.tomcat.websocket.server.WsSci.onStartup(WsSci.java:120)
... 12 more**

websocket(java)代码:

**import java.io.IOException;
import javax.websocket.ClientEndpoint;
import javax.websocket.OnError;
import javax.websocket.OnMessage;
import javax.websocket.OnOpen;
import javax.websocket.OnClose;
import javax.websocket.Session;
import javax.websocket.server.ServerEndpoint;
import java.util.concurrent.CopyOnWriteArraySet;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.*;
@ServerEndpoint("webDemo/chat")
public class ChatEntpoint{
private static final String GUEST_PREFIX = "访客";
private static final AtomicInteger connectionIds = new AtomicInteger(0);
private static final Set<ChatEntpoint> clientSet = new CopyOnWriteArraySet<>();
private final String nickname;
private Session session;
public ChatEntpoint(){
nickname = GUEST_PREFIX + connectionIds.getAndIncrement();
}
@OnOpen
public void start(Session session){
this.session = session;
clientSet.add(this);
String message = String.format("【%s %s】",nickname,"加入了聊天室!");
broadcast(message);
}
@OnClose
public void end(){
clientSet.remove(this);
String message = String.format("【%s %s】",nickname,"离开了聊天室!");
broadcast(message);
}
@OnMessage
public void incoming(String message){
String filteredMessage = String.format("【%s %s】",nickname,filter(message));
broadcast(filteredMessage);
}
@OnError
public void OnError(Throwable t) throws Throwable{
System.out.println("WebSocket服务器端错误" + t);
}
private static void broadcast(String msg){
for(ChatEntpoint client:clientSet){
try{
synchronized(client){
client.session.getBasicRemote().sendText(msg);
}
}
catch(IOException e){
System.out.println("聊天错误,向客户端"+client+"发送消息出现错误!");
clientSet.remove(client);
try{
client.session.close();
}
catch(IOException e1){}
String message = String.format("【%s %s】",client.nickname,"已经被断开了连接!");
broadcast(message);
}
}
}
private static String filter(String message){
if(message == null){
return null;
}
char content[] = new char[message.length()];
message.getChars(0,message.length(),content,0);
StringBuilder result = new StringBuilder(content.length + 50);
for(int i=0;i<content.length;i++){
switch(content[i]){
case '<':
result.append("&lt;");
break;
case '>':
result.append("&gt;");
break;
case '&':
result.append("&amp;");
break;
case '"':
result.append("&quot;");
break;
default:
result.append(content[i]);
}
}
return (result.toString());
}
}**

我尝试建立一个实时同步网站。我已经下载了tomcat 8.0,并在java中构建了websocket服务器。当我运行网络时,浏览器错误404。日志是这样写的:

我在网上搜索了很长时间。但没有用。请帮忙或尝试提供一些想法如何存档。

电脑配置:Windows-7 64位i5-3230M内存 4G

最佳答案

问题出在@ServerEndpoint 的值上。您在其值之前错过了 /

你应该使用这个:

@ServerEndpoint("/webDemo/chat")

关于tomcat - 由 : javax. websocket.DeploymentException 引起:路径 [websocket] 无效,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38417521/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com