gpt4 book ai didi

Tomcat:如何访问 Apache CXF-webapp 中的本地文件?

转载 作者:行者123 更新时间:2023-11-28 22:22:48 24 4
gpt4 key购买 nike

我有一个 tomcat 运行我的 CXF-based网络应用程序。

我使用的方法具有这样的签名:

@GET
@Path ("/handler/contract/{ItemId}")
@Produces ("application/xml")
public Item getItem(@PathParam("ItemId") Integer ItemId) throws Exception{
//...
return item;
}

这通常非常有用,因为我不必处理响应/请求对象并覆盖业务逻辑。

但现在我需要访问本地文件才能将其插入 PDF。我查看了此处和文档中的所有项目,但找不到可靠、简单的方法来访问 ContextRequest 以找到webapp 的当前路径,这样我就可以在展开的 WAR 中访问文件。

对于如何获取 CXF-webapp 的当前本地路径有什么帮助吗?

最佳答案

一如既往,如果您最终写了一篇文章,您将自己找到解决方案。使用 @Context 注释,您将获得正确的上下文。

@GET
@Path ("/handler/contract/{ItemId}")
@Produces ("application/xml")
public Item getItem(@Context ServletContext context, @PathParam("ItemId") Integer ItemId) throws Exception{
//retrieve the local path from the context
String currentLocalPath = context.getRealPath(".");
//...
return item;
}

感谢您的光临。 :)

关于Tomcat:如何访问 Apache CXF-webapp 中的本地文件?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7966100/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com