web.xml中servlet映射的URL模式 [英] URL Pattern for servlet mapping in web.xml
问题描述
我需要在web.xml中使用此URL映射来解决方法,以创建带字母的网址,后跟_后跟任意字母数字字符组合。
I need a workaround with this URL mapping in web.xml to create URLs with a letter, followed by a "_" followed by any combination of alphanumeric characters.
我想将servlet映射到这样的东西:
I want to map a servlet to something like this:
/something_*
而不是:
/something/*
为不同的JSP使用不同的somethings。示例:
Using different "somethings" for different JSP's. Example:
/search_Something-I-searched-for
我尝试使用:
<servlet-mapping>
<servlet-name>MyServlet</servlet-name>
<url-pattern>/something_*</url-pattern>
</servlet-mapping>
但这似乎不起作用。
这个答案告诉我,我可以不要在web.xml中这样做,所以也许有一些解决方法。
But this doesn't seem to work. This answer tells me I can't do this within web.xml, so maybe there's some workaround.
我不知道这些信息是否重要,但我在使用JBoss和Struts2我的项目。
I don't know if this information is important, but I'm using JBoss and Struts2 in my project.
推荐答案
将servlet映射到包含目录。在该servlet内部,拆开URL路径并转发到适当的命名为servlet 。
Map a servlet to the containing directory. Inside that servlet, take apart the URL path and forward to the appropriate named servlet.
这篇关于web.xml中servlet映射的URL模式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!