views:

290

answers:

2

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:

  1. A stray "." is still neither pretty nor clean.
  2. The class name is still capitalized in the URL..?
  3. That still leaves me with *.jsp..? Is it even possible to get rid of both .action and .jsp?
+3  A: 

I think you are looking for the @URLBinding annotation. Look at @URLBinding on your Bean.

@UrlBinding("/calculator")

Brian
I should have mentioned that I have tried this, but I then get a 404 when trying to access `http://mydomain.com/myapp/calculator`. Furthermore, I'd rather be establishing my own convention, rather than configuring by exception, on an action-by-action basis.
Dolph
The @URLBinding annotation definitely works.
Pointy