Of course It is possible. You could do It using mod_cgi.
A very simple example would be like this:
public class HelloWorld
{
public static void main(String[] args)
{
System.out.println("Hello Java CGI world!");
}
}
and then a script file (HelloWorld.shtml -do not forget the execute permission) that executes the Java class
#!/bin/bash
echo "Content-type: text/html"
echo ""
/usr/bin/java HelloWorld
In Apache conf, just define your script directory, something like this:
ScriptAlias /cgi-bin/ /Users/hectorsuarez/Proyectos/test/cgi-bin/
<Directory "/Users/hectorsuarez/Proyectos/test/cgi-bin">
SetHandler cgi-script
Options ExecCGI
Order allow,deny
Allow from all
</Directory>
That's it!. This is a very simple and trivial example.
This will get complicated because you could probably need a template engine and a much better way to manage the incoming CGI calls. But yes, It is possible.