问题
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