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

I want to use a pretty / clean url in my web application.

I need the following URL:

http://mydomain.com/myapp/calculator 

.. for solutions:

 com.mydomain.myapp.action.CalculatorActionBean 

I tried rewriting 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> 

What makes me:

 http://mydomain.com/myapp/Calculator. 

But:

  • Wandering "." still is neither beautiful nor pure.
  • The class name is still capitalized in the url.?
  • *.jsp it still leave me with *.jsp ..? Is it even possible to get rid of .action and .jsp ?
+4
source share
3 answers

I think you are looking for the @URLBinding annotation. Check out @URLBinding on Bean.

@UrlBinding ("/ calculator")

+4
source

I tried to do the same and had the same question, although I wanted my url to use the trailing slash http://mydomain.com/myapp/calculator/

The answer is to use @UrlBinding and DynamicMappingFilter

I modified the example to:

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

Then I added 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 never get redirected to the * .action URL after interacting with the form.

0
source

Source: https://habr.com/ru/post/1301398/


All Articles