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.
我需要在web.xml中使用此URL映射来解决方法,以创建带有字母的URL,后跟“_”后跟任何字母数字字符组合。
I want to map a servlet to something like this:
我想将servlet映射到这样的东西:
/something_*
Instead of:
/something/*
Using different "somethings" for different JSP's. Example:
为不同的JSP使用不同的“事物”。例:
/search_Something-I-searched-for
I tried using:
我试过用:
<servlet-mapping>
<servlet-name>MyServlet</servlet-name>
<url-pattern>/something_*</url-pattern>
</servlet-mapping>
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.
但这似乎不起作用。这个答案告诉我我不能在web.xml中这样做,所以也许有一些解决方法。
I don't know if this information is important, but I'm using JBoss and Struts2 in my project.
我不知道这些信息是否重要,但我在我的项目中使用JBoss和Struts2。
2 个解决方案
#1
Map a servlet to the containing directory. Inside that servlet, take apart the URL path and forward to the appropriate named servlet.
将servlet映射到包含目录。在该servlet中,拆分URL路径并转发到适当的命名servlet。
#2
Why not try Spring MVC Framework. Spring can offer that url mapping you want.
为什么不尝试Spring MVC Framework。 Spring可以提供你想要的url映射。
@RequestMapping(value="/something_{name}", method=RequestMethod.GET)
public String demo(@PathVariable(value="name") String name, ModelMap map) {
String something = name;
// Do manipulation
return "something"; // Forward to something.jsp
}
Watch this Spring MVC Framework Tutorial
观看这个Spring MVC框架教程
#1
Map a servlet to the containing directory. Inside that servlet, take apart the URL path and forward to the appropriate named servlet.
将servlet映射到包含目录。在该servlet中,拆分URL路径并转发到适当的命名servlet。
#2
Why not try Spring MVC Framework. Spring can offer that url mapping you want.
为什么不尝试Spring MVC Framework。 Spring可以提供你想要的url映射。
@RequestMapping(value="/something_{name}", method=RequestMethod.GET)
public String demo(@PathVariable(value="name") String name, ModelMap map) {
String something = name;
// Do manipulation
return "something"; // Forward to something.jsp
}
Watch this Spring MVC Framework Tutorial
观看这个Spring MVC框架教程