gpt4 book ai didi

jakarta-ee - 如何从 WebSocket 端点中获取真实的系统文件路径

转载 作者:行者123 更新时间:2023-12-03 10:02:51 25 4
gpt4 key购买 nike

当我在 Servlet 上下文中时,我可以通过调用 request.getServletContext().getRealPath(UPLOAD_PATH) 轻松获取真实的系统文件路径。 friend 们,请问我如何才能在 Java EE 7 的 WebSocket 端点内执行等效操作。提前致谢。

最佳答案

您可以从 ServerEndpointConfig#getPath() 中获取路径信息.此方法的结果与 ServletContext#getRealPath() 的唯一区别在于它给出了相关路径;您可以只在该方法的结果前加上根上下文名称。要获得结果,您需要实现onOpen(来自javax.websocket.Endpoint 类)

//called when the client first negotiates the opening of the websocket connection
public void onOpen(Session session, ServerEndpointConfig config){

String path = config.getPath();

}

关于jakarta-ee - 如何从 WebSocket 端点中获取真实的系统文件路径,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25967556/

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