我希望在我的网络应用中使用漂亮/干净的网址。
我想要以下网址:
http://mydomain.com/myapp/calculator
..解决:
com.mydomain.myapp.action.CalculatorActionBean
我尝试用:
覆盖NameBasedActionResolverpublic class CustomActionResolver extends NameBasedActionResolver {
public static final String DEFAULT_BINDING_SUFFIX = ".";
@Override
protected String getBindingSuffix() {
return DEFAULT_BINDING_SUFFIX;
}
@Override
protected List<String> getActionBeanSuffixes() {
List<String> suffixes = new ArrayList<String>(super.getActionBeanSuffixes());
suffixes.add(DEFAULT_BINDING_SUFFIX);
return suffixes;
}
}
并将其添加到web.xml
:
<servlet-mapping>
<servlet-name>StripesDispatcher</servlet-name>
<url-pattern>*.</url-pattern>
</servlet-mapping>
这让我:
http://mydomain.com/myapp/Calculator.
可是:
*.jsp
..?甚至可以摆脱.action
和.jsp
?答案 0 :(得分:4)
我认为您正在寻找@URLBinding注释。查看Bean上的@URLBinding。
@UrlBinding( “/运算部”)
答案 1 :(得分:0)
答案 2 :(得分:0)
我试图做同样的事情,并有同样的问题,但我希望我的网址使用尾部斜杠http://mydomain.com/myapp/calculator/
答案是使用@UrlBinding&amp; DynamicMappingFilter
我将示例修改为:
@UrlBinding("/calculator/")
public class CalculatorActionBean implements ActionBean {
.
.
.
return new ForwardResolution("/WEB-INF/view/calculator.jsp");
然后我将DMF添加到web.xml:
<filter>
<display-name>Stripes Dynamic Mapping Filter</display-name>
<filter-name>DynamicMappingFilter</filter-name>
<filter-class>net.sourceforge.stripes.controller.DynamicMappingFilter</filter-class>
<init-param>
<param-name>ActionResolver.Packages</param-name>
<param-value>com.example.stripes</param-value>
</init-param>
</filter>
<filter-mapping>
<filter-name>DynamicMappingFilter</filter-name>
<url-pattern>/*</url-pattern>
<dispatcher>REQUEST</dispatcher>
<dispatcher>FORWARD</dispatcher>
<dispatcher>INCLUDE</dispatcher>
</filter-mapping>
现在干净的URL按预期工作,在与表单交互后,我永远不会被重定向到* .action URL。