How to remove the file suffix/extension (.jsp and .action) using the Stripes Framework?
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:
- A stray "." is still neither pretty nor clean.
- The class n开发者_高级运维ame is still capitalized in the URL..?
- 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.
精彩评论