In the first step we will just enable Madvoc and prepare it for future enhancements.
Lets register Madvoc in web.xml.
... <!-- filters --> <filter> <filter-name>madvoc</filter-name> <filter-class>jodd.madvoc.MadvocServletFilter</filter-class> </filter> <filter-mapping> <filter-name>madvoc</filter-name> <url-pattern>/*</url-pattern> <dispatcher>REQUEST</dispatcher> <dispatcher>INCLUDE</dispatcher> <dispatcher>FORWARD</dispatcher> </filter-mapping> ...
This is the minimum configuration of Madvoc.
Lets add dummy index action.
import jodd.madvoc.meta.MadvocAction;
import jodd.madvoc.meta.Action;
@MadvocAction
public class IndexAction {
@Action
public void view() {}
}
Now action path /index.html is mapped to IndexAction#view() action that renders index.jsp.
Tomcat can't use Madvocs action (or any 'dynamic' path) as a welcome file. To make /index.html to be one of welcome files, we need to redirect to it from simple JSP page:
... <welcome-file-list> <welcome-file>redirect.jsp</welcome-file> </welcome-file-list> ...redirect.jsp
<jsp:forward page="/index.html"/>
Madvoc and JSP should use the same encoding, which is by default UTF8. We can set encoding for all JSP files in web.xml:
... <jsp-config> <jsp-property-group> <url-pattern>*.jsp</url-pattern> <page-encoding>UTF-8</page-encoding> </jsp-property-group> </jsp-config> ...
Minimal Madvoc configuration is often not enough. We will immediately extend it; doing this early is consider as good practice. Note that in Jodd, all customization is done using pure Java, usually by extending some classes. The same is here - we will add our AppWebApplication by extending the WebApplication and register it in web.xml.
import jodd.madvoc.WebApplication;
/**
* Web application.
*/
public class AppWebApplication extends WebApplication {
}
web.xml changes
... <filter> <filter-name>madvoc</filter-name> <filter-class>jodd.madvoc.MadvocServletFilter</filter-class> <init-param> <param-name>madvoc.webapp</param-name> <param-value>com....AppWebApplication</param-value> </init-param> </filter> ...
Now we are ready for all possible Madvoc extensions and customization.
Lets enable Madvoc file parameters, in case we need them.
... <filter> <filter-name>madvoc</filter-name> <filter-class>jodd.madvoc.MadvocServletFilter</filter-class> <init-param> <param-name>madvoc.webapp</param-name> <param-value>com....AppWebApplication</param-value> </init-param> <init-param> <param-name>madvoc.params</param-name> <param-value>/madvoc.properties</param-value> </init-param> </filter> ...
Add empty madvoc.properties to classpath root.