如何将服务器端 Jax-rs 调用与不带前缀的本机文件混合? [英] How to mix server-side Jax-rs call with native files without prefix?

查看:37
本文介绍了如何将服务器端 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_REGEXServletContainer.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 调用与不带前缀的本机文件混合?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆