Jodd集成

需要配置web.xml,将所有请求交给jodd处理,参考:http://jodd.org/doc/madvoc/setup.html

  1. <filter>
  2. <filter-name>madvoc</filter-name>
  3. <filter-class>jodd.madvoc.MadvocServletFilter</filter-class>
  4. <init-param>
  5. <param-name>madvoc.webapp</param-name>
  6. <param-value>test.MyWebApplication</param-value>
  7. </init-param>
  8. <init-param>
  9. <param-name>madvoc.configurator</param-name>
  10. <param-value>test.MyAutomagicMadvocConfigurator</param-value>
  11. </init-param>
  12. </filter>
  13. <filter-mapping>
  14. <filter-name>madvoc</filter-name>
  15. <url-pattern>/*</url-pattern>
  16. </filter-mapping>

MyWebApplication 和 MyAutomagicMadvocConfigurator 需要自己参照如下例子写一个,前者用来设置beetl作为视图渲染,后者配置Jodd不要扫描beetl struts集成里引用的struts类

  1. public class MyAutomagicMadvocConfigurator extends AutomagicMadvocConfigurator {
  2. public MyAutomagicMadvocConfigurator(){
  3. super();
  4. //不扫描beetl 里jar文件里的action和result,否则,会扫描StrutsResultSupport不相干的class
  5. this.rulesJars.exclude("**/*beetl*.jar");
  6. }
  7. }
  1. public class MyWebApplication extends WebApplication{
  2. @Override
  3. protected void init(MadvocConfig madvocConfig, ServletContext servletContext) {
  4. //设置默认
  5. madvocConfig.setDefaultActionResult(BeetlActionResult.class);
  6. }
  7. }

最后,可以写Action了,浏览器输入/index.html,jodd将执行world方法,并渲染ok.html模板。如果你想配置GroupTemplate,正如其他集成框架一样,只需要写一个beetl.properties 即可。

  1. @MadvocAction
  2. public class IndexAction {
  3. @Out
  4. String value;
  5. @Action("/index.html")
  6. public String world() {
  7. value = "Hello World!";
  8. return "/ok.html";
  9. }
  10. }

https://git.oschina.net/xiandafu/beetl-jodd-sample 有完整例子