在RESTLET中读取Web-INF中的配置文件 [英] Reading config files within Web-INF in RESTLET

查看:133
本文介绍了在RESTLET中读取Web-INF中的配置文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试读取位于WEB-INF根路径内的配置文件.该应用程序正在使用RESTLET框架.我阅读了官方的RESTLET

I'm trying to read a config file placed inside the root path of WEB-INF. The application is using RESTLET framework. I read in the official RESTLET doc that its possible to read files via a WAR connector ("war:///WEB-INF/web.xml") using Context.getClientDispatcher().

但是我无法弄清楚该如何实现.请告知我有关此信息或使用RESTLET读取文件的任何其他方式

However i was not able to figure out as to how this can be achieved. Kindly let me know about this or any other ways a file can be read using RESTLET

推荐答案

找到了解决方案.我必须访问ServletContext才能进入配置文本文件.这是代码示例-

Found the solution for this. I had to access the ServletContext to get to the configuration text file. Here is the code sample -

// Extract the ServletContext from the attributes of RestletContext
    ServletContext servlet = (ServletContext) context.getAttributes().get("org.restlet.ext.servlet.ServletContext");
// Get the path of the config file relative to the WAR
    String rootPath = servlet.getRealPath("/WEB-INF/configuration.txt");
    Path path = Paths.get(rootPath);
    File configFile = new File(path.toString());
    FileRepresentation file = new FileRepresentation(configFile, MediaType.TEXT_PLAIN);

这篇关于在RESTLET中读取Web-INF中的配置文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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