Question

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?
Was it helpful?

Solution

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

@UrlBinding("/calculator")

OTHER TIPS

I was trying to do the same thing, and had the same question, though I wanted my URL to use the trailing slash http://mydomain.com/myapp/calculator/

The answer is to use @UrlBinding & the DynamicMappingFilter

I modified the example to have:

@UrlBinding("/calculator/")
public class CalculatorActionBean implements ActionBean {
  .
  .
  .
return new ForwardResolution("/WEB-INF/view/calculator.jsp");

Then I added the DMF to web.xml:

<filter>
    <display-name>Stripes Dynamic Mapping Filter</display-name>
    <filter-name>DynamicMappingFilter</filter-name>
    <filter-class>net.sourceforge.stripes.controller.DynamicMappingFilter</filter-class>
    <init-param>
        <param-name>ActionResolver.Packages</param-name>
        <param-value>com.example.stripes</param-value>
    </init-param>
</filter>

<filter-mapping>
    <filter-name>DynamicMappingFilter</filter-name>
    <url-pattern>/*</url-pattern>
    <dispatcher>REQUEST</dispatcher>
    <dispatcher>FORWARD</dispatcher>
    <dispatcher>INCLUDE</dispatcher>
</filter-mapping>

Now the clean URL works as expected, and I'm never redirected to a *.action URL after interacting with the form.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top