How can I get real system file path from within a WebSocket Endpoint

瘦欲@ 提交于 2019-12-13 13:51:12

问题


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.


回答1:


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();

}


来源:https://stackoverflow.com/questions/25967556/how-can-i-get-real-system-file-path-from-within-a-websocket-endpoint

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!