Converting a Stripes application to use Friendly URLs
Asked Answered
E

2

5

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.

Here is the before ...

index.jsp:

<jsp:forward page="/Hello.action"/>

web.xml:

<servlet-mapping>
    <servlet-name>DispatcherServlet</servlet-name>
    <url-pattern>*.action</url-pattern>
</servlet-mapping>

and I have no UrlBinding on my HelloActionBean. I have the book example working.

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:

<jsp:forward page="/hello"/>

web.xml:

<servlet-mapping>
    <servlet-name>DispatcherServlet</servlet-name>
    <url-pattern>/*</url-pattern>
 </servlet-mapping>

HelloActionBean.java:

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

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)

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.

Eadmund answered 7/4, 2009 at 12:48 Comment(0)
E
6

I've been trying out a few other things and got it working ...

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=

becomes

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

change the UrlBinding on the ActionBean to:

@UrlBinding("/hello/{$event}")
Eadmund answered 7/4, 2009 at 13:52 Comment(0)
Y
1

It didn't work for me to just replace the Dispatcher servlet with the DynamicMappingFilter (I got an error message about the DynamicMappingFilter only works in conjunction with the StripesFilter). So I have two filters and one filter-mapping configured in my web.xml now:

<filter>
    <display-name>Stripes Filter</display-name>
    <filter-name>StripesFilter</filter-name>
    <filter-class>net.sourceforge.stripes.controller.StripesFilter</filter-class>
    <init-param>
        <param-name>ActionResolver.Packages</param-name>
        <param-value>com.package.myactions.package</param-value>
    </init-param>
</filter>

<filter>
    <description>Dynamically maps URLs to ActionBeans.</description>
    <display-name>Stripes Dynamic Mapping Filter</display-name>
    <filter-name>DynamicMappingFilter</filter-name>
    <filter-class>
        net.sourceforge.stripes.controller.DynamicMappingFilter
    </filter-class>
</filter>

<filter-mapping>
    <filter-name>DynamicMappingFilter</filter-name>
    <url-pattern>/*</url-pattern>
    <dispatcher>REQUEST</dispatcher>
    <dispatcher>FORWARD</dispatcher>
    <dispatcher>INCLUDE</dispatcher>
</filter-mapping>
Yiddish answered 20/8, 2009 at 13:5 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.