如何在web.xml或Guice servlet模块中排除/重定向某些url模式? [英] How to exclude/redirect certain url pattern in web.xml or Guice servlet module?

查看:169
本文介绍了如何在web.xml或Guice servlet模块中排除/重定向某些url模式?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要使用url模式/ *为我的主应用程序提供服务,以便此模式与Servlet匹配。
我遇到的问题是现在位于/css/all.css,/ images /等的所有css文件和图像都经过这个Servlet,这是不可取的。我希望直接访问这些文件。
处理这种情况的更好方法是什么?

I need to serve my main application with the url pattern "/*" so this pattern is matched to a Servlet. The problem I am having is now all the css files and images located at "/css/all.css", "/images/" etc are going through this Servlet which is undesirable. I want these files to be directly accessed. What is the better way to handle this situation?

注意:我使用Guice的Servlet模块来配置模式。

Note: I am using Guice's Servlet Module to configure the patterns.

谢谢!

推荐答案

我们需要具体了解哪些请求应该路由到您的servlet,以便我们知道如何编写规则。我不知道是否a)除了CSS和图像之外的所有请求都应该发送到你的servlet,或者b)你的servlet应该只处理对特定文件夹/目录集的请求。您可能想要做以下两件事之一:

We need to know specifically which requests should be routed to your servlet, so that we know how to code the rules. I can't tell whether a) all requests except CSS and images should be sent to your servlet, or b) your servlet should only handle requests to a specific set of folders/directories. You will probably want to do one of two things:

排除特定文件夹:

^/(?!css|images).*

或包含特定文件夹:

^/myservlet/.*

您应该将 * 符号更改为 + 如果您在之前的问题中指出,您希望在模式中 / 之后至少需要一个字符。

You should change those * symbols to + if, as you indicated in your earlier question, you want to require at least one character after the / in the pattern.

这篇关于如何在web.xml或Guice servlet模块中排除/重定向某些url模式?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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