如何从WebSocket端点获取真实的系统文件路径 [英] How can I get real system file path from within a WebSocket Endpoint
问题描述
当我在Servlet上下文中时,我可以通过调用request.getServletContext()。getRealPath(UPLOAD_PATH)轻松获取真实的系统文件路径。请朋友们如何在Java EE 7中的WebSocket端点内完成等效操作。提前感谢。
While I am within a Servlet Context I can easily get the real system file path by calling on request.getServletContext().getRealPath(UPLOAD_PATH). Please friends how can I do the equivalent from within a WebSocket Endpoint in Java EE 7. Thanks in advance.
推荐答案
你可以得到来自 ServerEndpointConfig #getPath()的路径信息。此方法的结果与 ServletContext#getRealPath()
之间的唯一区别是,它给出了相关路径;您可以使用根上下文名称为该方法的结果添加前缀。要获得结果,您需要实现 onOpen
(来自 javax.websocket.Endpoint
类)
You can get path information from the ServerEndpointConfig#getPath(). The only difference between the results of this method and ServletContext#getRealPath()
is that this gives the relateive path; you could just prefix the results of that method with the root context name. To get the results, you need to implement onOpen
(from the javax.websocket.Endpoint
class)
//called when the client first negotiates the opening of the websocket connection
public void onOpen(Session session, ServerEndpointConfig config){
String path = config.getPath();
}
这篇关于如何从WebSocket端点获取真实的系统文件路径的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!