当我在 Servlet 上下文中时,我可以通过调用 request.getServletContext().getRealPath(UPLOAD_PATH) 轻松获取真实的系统文件路径。请问朋友们,我怎样才能在 Java EE 7 中的 WebSocket 端点中执行相同的操作。提前致谢。
您可以从以下位置获取路径信息ServerEndpointConfig#getPath() http://docs.oracle.com/javaee/7/api/javax/websocket/server/ServerEndpointConfig.html#getPath()。该方法的结果与该方法的唯一区别ServletContext#getRealPath()
是这给出了相对路径;您只需在该方法的结果前面加上根上下文名称即可。要获得结果,您需要实施onOpen
(来自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();
}
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)