The Unbearable Lightness of Java

View with Madvoc

In the first step we will just enable Madvoc and prepare it for future enhancements.

web.xml

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.

Index action

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.

Madvoc action as welcome file

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:

web.xml
...
<welcome-file-list>
	<welcome-file>redirect.jsp</welcome-file>
</welcome-file-list>
...
redirect.jsp
<jsp:forward page="/index.html"/>

Use the same encoding

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>
...

Custom web application

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.

new class
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.

Parameters

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.