如何使用 Stripes 框架删除文件后缀/扩展名(.jsp 和 .action)?
我希望在我的网络应用程序中使用漂亮/干净的 URL。
我想要以下 URL:
http://mydomain.com/myapp/calculator
.. 解析为:
com.mydomain.myapp.action.CalculatorActionBean
我尝试用以下内容覆盖 NameBasedActionResolver:
public 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.
但是:
- 一个流浪的“.”仍然既不漂亮也不干净。
- URL 中的类名仍然大写..?
- 那仍然让我留下
*.jsp
..?是否有可能同时摆脱.action
和.jsp
?
I'm looking to use pretty / clean URL's in my web app.
I would like the following URL:
http://mydomain.com/myapp/calculator
.. to resolve to:
com.mydomain.myapp.action.CalculatorActionBean
I tried overwriting the NameBasedActionResolver with:
public 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;
}
}
And adding this to web.xml
:
<servlet-mapping>
<servlet-name>StripesDispatcher</servlet-name>
<url-pattern>*.</url-pattern>
</servlet-mapping>
Which gets me to:
http://mydomain.com/myapp/Calculator.
But:
- A stray "." is still neither pretty nor clean.
- The class name is still capitalized in the URL..?
- That still leaves me with
*.jsp
..? Is it even possible to get rid of both.action
and.jsp
?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我认为您正在寻找 @URLBinding 注释。查看 @URLBinding豆。
@UrlBinding("/计算器")
I think you are looking for the @URLBinding annotation. Look at @URLBinding on your Bean.
@UrlBinding("/calculator")
尝试使用DMF
http://stripes.sourceforge.net/文档/current/javadoc/net/sourceforge/stripes/controller/DynamicMappingFilter.html
Try to use DMF
http://stripes.sourceforge.net/docs/current/javadoc/net/sourceforge/stripes/controller/DynamicMappingFilter.html
我试图做同样的事情,并且有同样的问题,尽管我希望我的 URL 使用尾部斜杠
http://mydomain.com/myapp/calculator/
答案是使用 @ UrlBinding & DynamicMappingFilter
我将示例修改为:
然后我将 DMF 添加到 web.xml:
现在干净的 URL 按预期工作,并且在与表单交互后我永远不会重定向到 *.action URL。
I was trying to do the same thing, and had the same question, though I wanted my URL to use the trailing slash
http://mydomain.com/myapp/calculator/
The answer is to use @UrlBinding & the DynamicMappingFilter
I modified the example to have:
Then I added the DMF to web.xml:
Now the clean URL works as expected, and I'm never redirected to a *.action URL after interacting with the form.