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 调用与不带前缀的本机文件混合?
基础教程推荐
- 使用堆栈算法进行括号/括号匹配 2022-01-01
- RabbitMQ:消息保持“未确认"; 2022-01-01
- 如何对 Java Hashmap 中的值求和 2022-01-01
- 存储 20 位数字的数据类型 2022-01-01
- Spring AOP错误无法懒惰地为此建议构建thisJoinPoin 2022-09-13
- Struts2 URL 无法访问 2022-01-01
- 问题http://apache.org/xml/features/xinclude测试日志4j 2 2022-01-01
- 无法复制:“比较方法违反了它的一般约定!" 2022-01-01
- REST Web 服务返回 415 - 不支持的媒体类型 2022-01-01
- 修改 void 函数的输入参数,然后读取 2022-01-01
