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

And*_*use 5 java stripes

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

这是之前...

的index.jsp:

<jsp:forward page="/Hello.action"/>
Run Code Online (Sandbox Code Playgroud)

web.xml中:

<servlet-mapping>
    <servlet-name>DispatcherServlet</servlet-name>
    <url-pattern>*.action</url-pattern>
</servlet-mapping>
Run Code Online (Sandbox Code Playgroud)

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

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

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

的index.jsp:

<jsp:forward page="/hello"/>
Run Code Online (Sandbox Code Playgroud)

web.xml中:

<servlet-mapping>
    <servlet-name>DispatcherServlet</servlet-name>
    <url-pattern>/*</url-pattern>
 </servlet-mapping>
Run Code Online (Sandbox Code Playgroud)

HelloActionBean.java:

**@UrlBinding("/hello")**
public class HelloActionBean implements ActionBean 
{
Run Code Online (Sandbox Code Playgroud)

但是,当我尝试通过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)
Run Code Online (Sandbox Code Playgroud)

如果我通过http:// localhost:8080/getting_started/hello访问它,服务器似乎进入循环,抛出一个接一个的异常.

任何建议表示赞赏 - 谢谢.

And*_*use 6

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

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

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

http://localhost:8080/getting_started/hello?randomDate=
Run Code Online (Sandbox Code Playgroud)

http://localhost:8080/getting_started/hello/randomDate
Run Code Online (Sandbox Code Playgroud)

将ActionBean上的UrlBinding更改为:

@UrlBinding("/hello/{$event}")
Run Code Online (Sandbox Code Playgroud)