转换Stripes应用程序以使用友好URL

我正在研究Fred Daoud的Stripes一书,并尝试将Hello World应用程序转换为使用友好URL,因为我不是基于后缀的映射的忠实粉丝,如http:// localhost:8080 / getting_started / Hello.action 。

这是之前…

的index.jsp:

 

web.xml中:

  DispatcherServlet *.action  

我的HelloActionBean上没有UrlBinding。 我有书的例子。

我想知道这些书的例子是否适合Stripes的早期版本,因为我已经下载了1.5.1并且我的web.xml定义了StripesFilter和StripesDispatcher,而我看到了其他地方使用的DynamicMappingFilter,例如Fred的这篇文章在TheServerSide上。

无论如何,我做了以下更改:

的index.jsp:

  

web.xml中:

  DispatcherServlet /*  

HelloActionBean.java:

 **@UrlBinding("/hello")** public class HelloActionBean implements ActionBean { 

但是,当我尝试通过http:// localhost:8080 / getting_started加载应用程序时,我看到:

 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访问它,服务器似乎进入循环,抛出一个接一个的exception。

任何建议表示赞赏 – 谢谢。

我一直在尝试其他一些东西,让它工作……

我删除了web.xml中现有的DispatcherServlet servlet和servlet-mapping定义,并替换为DynamicMappingFilter。

作为奖励,改变链接事件的传递方式,例如

 http://localhost:8080/getting_started/hello?randomDate= 

 http://localhost:8080/getting_started/hello/randomDate 

将ActionBean上的UrlBinding更改为:

 @UrlBinding("/hello/{$event}") 

用DynamicMappingFilter替换Dispatcher servlet不起作用(我得到一条关于DynamicMappingFilter的错误消息只能与StripesFilter一起使用)。 所以我现在在web.xml中配置了两个filter和一个filter映射:

  Stripes Filter StripesFilter net.sourceforge.stripes.controller.StripesFilter  ActionResolver.Packages com.package.myactions.package    Dynamically maps URLs to ActionBeans. Stripes Dynamic Mapping Filter DynamicMappingFilter  net.sourceforge.stripes.controller.DynamicMappingFilter    DynamicMappingFilter /* REQUEST FORWARD INCLUDE