Sri*_*nta 2 java servlets restlet restlet-2.0
我正在尝试读取放置在WEB-INF根路径中的配置文件.该应用程序正在使用RESTLET框架.我在官方RESTLET 文档中读到可以使用Context.getClientDispatcher()通过WAR连接器("war:///WEB-INF/web.xml")读取文件.
但是我无法弄清楚如何实现这一目标.请告诉我这个或任何其他方式使用RESTLET读取文件
找到了解决方案.我不得不访问ServletContext来获取配置文本文件.这是代码示例 -
// 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);
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
516 次 |
| 最近记录: |