开发者

How to remove the file suffix/extension (.jsp and .action) using the Stripes Framework?

开发者 https://www.devze.com 2022-12-20 11:52 出处:网络
I\'m looking to use pretty / clean URL\'s in my web app. I would like the following URL: http://mydomain.com/myapp/calculator

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 n开发者_高级运维ame 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?


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

@UrlBinding("/calculator")


Try to use DMF http://stripes.sourceforge.net/docs/current/javadoc/net/sourceforge/stripes/controller/DynamicMappingFilter.html


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消