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 调用与不带前缀的本机文件混合?


基础教程推荐
- 设置 bean 时出现 Nullpointerexception 2022-01-01
- 在 Libgdx 中处理屏幕的正确方法 2022-01-01
- 如何使用 Java 创建 X509 证书? 2022-01-01
- Java:带有char数组的println给出乱码 2022-01-01
- 无法使用修饰符“public final"访问 java.util.Ha 2022-01-01
- 减少 JVM 暂停时间 >1 秒使用 UseConcMarkSweepGC 2022-01-01
- FirebaseListAdapter 不推送聊天应用程序的单个项目 - Firebase-Ui 3.1 2022-01-01
- Java Keytool 导入证书后出错,"keytool error: java.io.FileNotFoundException &拒绝访问" 2022-01-01
- 降序排序:Java Map 2022-01-01
- “未找到匹配项"使用 matcher 的 group 方法时 2022-01-01