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

时间:2014-09-22 06:03:57

标签: java-ee websocket java-ee-7

当我在Servlet上下文中时,我可以通过调用request.getServletContext()。getRealPath(UPLOAD_PATH)轻松获取真实的系统文件路径。请朋友们如何在Java EE 7中的WebSocket端点内完成相应的操作。提前感谢。

1 个答案:

答案 0 :(得分:0)

您可以从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();

}
相关问题