转换Stripes应用程序以使用友好URL [英] Converting a Stripes application to use Friendly URLs
问题描述
我正在研究Fred Daoud的Stripes一书并尝试将Hello World应用程序转换为使用友好URL,因为我不是基于后缀的映射的忠实粉丝,如 http:// localhost:8080 / getting_started / Hello.action 。
I am working through Fred Daoud's Stripes book and trying to convert the Hello World application to use friendly URLs, as I'm not a big fan of suffix-based mappings like http://localhost:8080/getting_started/Hello.action.
这是以前的...
index.jsp:
index.jsp:
<jsp:forward page="/Hello.action"/>
web.xml:
<servlet-mapping>
<servlet-name>DispatcherServlet</servlet-name>
<url-pattern>*.action</url-pattern>
</servlet-mapping>
我的HelloActionBean上没有UrlBinding。我让这本书的例子有效。
and I have no UrlBinding on my HelloActionBean. I have the book example working.
我想知道这些书的例子是否适合早期版本的Stripes,因为我已经下载了1.5.1和我的网页。 xml定义了StripesFilter和StripesDispatcher,而我见过在其他地方使用的DynamicMappingFilter,例如在Fred的TheServerSide上这篇文章中。
I'm wondering if the book examples may suit an earlier version of Stripes, as I've downloaded 1.5.1 and my web.xml defines the StripesFilter and StripesDispatcher whereas I've seen a DynamicMappingFilter used elsewhere, e.g. in this article by Fred on TheServerSide.
无论如何,我做了以下更改:
Anyway, I made the following changes:
index.jsp:
index.jsp:
<jsp:forward page="/hello"/>
web.xml:
<servlet-mapping>
<servlet-name>DispatcherServlet</servlet-name>
<url-pattern>/*</url-pattern>
</servlet-mapping>
HelloActionBean.java:
HelloActionBean.java:
**@UrlBinding("/hello")**
public class HelloActionBean implements ActionBean
{
但是,当我尝试通过 http:// localhost:8080加载应用程序时/ getting_started 我看到了:
However, when I try to load the app through http://localhost:8080/getting_started I see this:
net.sourceforge.stripes.exception.ActionBeanNotFoundException: Could not locate an ActionBean that is bound to the URL [/]. Commons reasons for this include mis-matched URLs and forgetting to implement ActionBean in your class. Registered ActionBeans are: {/hello=class stripesbook.action.HelloActionBean, /controller/DefaultView.action=class net.sourceforge.stripes.controller.DefaultViewActionBean, /hello/=class stripesbook.action.HelloActionBean, /controller/DefaultView.action/=class net.sourceforge.stripes.controller.DefaultViewActionBean}
at net.sourceforge.stripes.controller.AnnotatedClassActionResolver.getActionBean(AnnotatedClassActionResolver.java:341)
如果我通过 http:// localhost访问它: 8080 / getting_started / hello 服务器似乎进入循环,抛出一个接一个的异常。
and if I access it through http://localhost:8080/getting_started/hello the server seems to go into a loop throwing one exception after another.
任何建议表示赞赏 - 谢谢。
Any suggestions appreciated - thanks.
推荐答案
我一直在尝试其他一些事情让它运转起来......
I've been trying out a few other things and got it working ...
我删除了web.xml中现有的DispatcherServlet servlet和servlet-mapping定义,并替换为wit h DynamicMappingFilter。
I removed the existing DispatcherServlet servlet and servlet-mapping definitions in web.xml and replaced with the DynamicMappingFilter.
作为奖励,改变链接事件的传递方式,以便例如
As a bonus, to change the way link events are passed, so that e.g.
http://localhost:8080/getting_started/hello?randomDate=
变为
http://localhost:8080/getting_started/hello/randomDate
将ActionBean上的UrlBinding更改为:
change the UrlBinding on the ActionBean to:
@UrlBinding("/hello/{$event}")
这篇关于转换Stripes应用程序以使用友好URL的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!