如何从WebSocket端点获取真实的系统文件路径 [英] How can I get real system file path from within a WebSocket Endpoint

查看:755
本文介绍了如何从WebSocket端点获取真实的系统文件路径的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我在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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆