How to mix server-side Jax-rs call with native files without prefix?(如何将服务器端 Jax-rs 调用与不带前缀的本机文件混合?)
问题描述
我们目前正在使用 Jersey JAX-RS 实现来处理我们的 REST 请求(服务器端 Jersey).我们的 web.xml 文件已配置,因此所有/rest/* 请求都由 Jersey 处理.没关系.我们的服务器目前是 Tomcat6,并且使用 Java6(在 Ubuntu 11.04 上)
We are currently using a Jersey JAX-RS implementation to handle our REST requests (server-side Jersey). Our web.xml file is configured so all /rest/* requests are handled by Jersey. That's fine. Our server is currently Tomcat6, and using Java6 ( on Ubuntu 11.04 )
所以,://myserver/rest/customer/没问题,Jersey 调用带有 @Path("/customer") 前缀的类.
So, ://myserver/rest/customer/ is ok and Jersey calls the class with @Path("/customer") prefix.
现在我们还有静态内容,例如 ://myserver/images/... 加载正常.
Now we also have static content, for example ://myserver/images/... wich loads fine.
有没有办法让我们摆脱/rest/* 前缀并将它们混合在一起?
Is there a way to do so that we can get rid of the /rest/* prefix and mix it all together?
我们想要达到的目标:://myserver/rest/customer/→ 泽西岛://myserver/rest/images/→ 战争的原生镜像目录
What we want to achieve : ://myserver/rest/customer/ → Jersey ://myserver/rest/images/ → the native image Directory of the war
感谢您的帮助
推荐答案
这很容易实现.只需在 web.xml 中注册 Jersey ServletContainer 作为过滤器(而不是 servlet) - 参见 this page - 或者使用 ServletContainer.PROPERTY_WEB_PAGE_CONTENT_REGEX 或 ServletContainer.FEATURE_FILTER_FORWARD_ON_404 初始化参数以使静态内容可访问.
This is pretty easy to achieve. Just register Jersey ServletContainer in web.xml as a filter (instead of servlet) - see the bottom of this page for an example - and either use ServletContainer.PROPERTY_WEB_PAGE_CONTENT_REGEX or ServletContainer.FEATURE_FILTER_FORWARD_ON_404 init param to make the static content accessible.
这篇关于如何将服务器端 Jax-rs 调用与不带前缀的本机文件混合?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:如何将服务器端 Jax-rs 调用与不带前缀的本机文件混合?


- Jersey REST 客户端:发布多部分数据 2022-01-01
- value & 是什么意思?0xff 在 Java 中做什么? 2022-01-01
- 如何使用WebFilter实现授权头检查 2022-01-01
- Java包名称中单词分隔符的约定是什么? 2022-01-01
- Eclipse 插件更新错误日志在哪里? 2022-01-01
- Safepoint+stats 日志,输出 JDK12 中没有 vmop 操作 2022-01-01
- 从 finally 块返回时 Java 的奇怪行为 2022-01-01
- C++ 和 Java 进程之间的共享内存 2022-01-01
- 将log4j 1.2配置转换为log4j 2配置 2022-01-01
- Spring Boot连接到使用仲裁器运行的MongoDB副本集 2022-01-01