4.7. Jodd集成
需要配置web.xml,将所有请求交给jodd处理,参考:http://jodd.org/doc/madvoc/setup.html
<filter>
<filter-name>madvoc</filter-name>
<filter-class>jodd.madvoc.MadvocServletFilter</filter-class>
<init-param>
<param-name>madvoc.webapp</param-name>
<param-value>test.MyWebApplication</param-value>
</init-param>
<init-param>
<param-name>madvoc.configurator</param-name>
<param-value>test.MyAutomagicMadvocConfigurator</param-value>
</init-param>
</filter>
<filter-mapping>
<filter-name>madvoc</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
MyWebApplication 和 MyAutomagicMadvocConfigurator 需要自己参照如下例子写一个,前者用来设置beetl作为视图渲染,后者配置Jodd不要扫描beetl struts集成里引用的struts类
public class MyAutomagicMadvocConfigurator extends AutomagicMadvocConfigurator {
public MyAutomagicMadvocConfigurator(){
super();
//不扫描beetl 里jar文件里的action和result,否则,会扫描StrutsResultSupport不相干的class
this.rulesJars.exclude("**/*beetl*.jar");
}
}
public class MyWebApplication extends WebApplication{
@Override
protected void init(MadvocConfig madvocConfig, ServletContext servletContext) {
//设置默认
madvocConfig.setDefaultActionResult(BeetlActionResult.class);
}
}
最后,可以写Action了,浏览器输入/index.html,jodd将执行world方法,并渲染ok.html模板。如果你想配置GroupTemplate,正如其他集成框架一样,只需要写一个beetl.properties 即可。
@MadvocAction
public class IndexAction {
@Out
String value;
@Action("/index.html")
public String world() {
value = "Hello World!";
return "/ok.html";
}
}
当前内容版权归 ibeetl.com 或其关联方所有,如需对内容或内容相关联开源项目进行关注与资助,请访问 ibeetl.com .