FemtoWeb

Setup

It is really easy to set up FemtoWeb for your project. You only have to add a simple JAR (and two additional libraries) to your classpath like any other dependency.

Note that the JAR is available for manual download in a package distribution on the official download page. Moreover, the artifact com.quartercode:femtoweb is available both in the maven central repository and the LoadingByte maven repository (https://repo.loadingbyte.com/content/groups/maven-public/).

First step: JAR

Maven

If you build with maven, you only have to add the FemtoWeb dependency (available in maven central) to the pom.xml of your maven project (change VERSION to the version of FemtoWeb you want to use):

<dependency>
    <groupId>com.quartercode</groupId>
    <artifactId>femtoweb</artifactId>
    <version>VERSION</version>
</dependency>

Of course, the FemtoWeb JAR and the additional libraries must also be part of the classpath at runtime. If you do not already have a system in place for that, you might want to use the Maven Shade Plugin.

Other

Depending on your build environment, this process might be very different. It is important that the following three JARs are on the classpath both at compilation time and at runtime. That means that those JARs must somehow be packaged with your final application.

Eclipse

If you are using Eclipse (and not already using maven), you need to tell Eclipse it should add the three JARs to the classpath. You can do that by following this tutorial for all three JARs.

Second step: Configuration

FemtoWeb is designed to require as little configuration as possible. To get it up and running you simply need to configure the FemtoWeb filter in your web application's web.xml like this:

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" version="3.0">
    ...

    <filter>
        <filter-name>femtoweb</filter-name>
        <filter-class>com.quartercode.femtoweb.impl.FemtoWebFilter</filter-class>
        <init-param>
            <param-name>actionBasePackage</param-name>
            <param-value>{ACTION_BASE_PACKAGE}</param-value>
        </init-param>
    </filter>
    <filter-mapping>
        <filter-name>femtoweb</filter-name>
        <url-pattern>/*</url-pattern>
    </filter-mapping>

    ...
</web-app>

You can see that it is necessary to configure the "action base package" of your webapp. Apart from that required parameter, there are some other configuration options available. The following table lists them all.

Option Example Description Required Default
actionBasePackage com.quartercode.mywebapp.actions The base package where all action classes are located in (subpackages of this package are allowed as well). See the action page for more information on actions. Yes -
staticAssetPath /path/to/static/files The path under which static resources (e.g. CSS stylesheets, JavaScript files or images) are located. Requests to such static resources are not handled as requests to actions. A static request is directly answered with the content of the requested static file. This path is relative to the root directory of the webapp (the directory which also contains the WEB-INF folder). It is important that this path doesn't reference a directory inside /WEB-INF; otherwise, the static files cannot be displayed! No /static
dynamicAssetPath /WEB-INF/path/to/dynamic/files The path under which dynamic resources (e.g. JSP files) are located. This path is relative to the root directory of the webapp (the directory which also contains the WEB-INF/ folder). It is recommended that this path references a directory inside /WEB-INF; otherwise, the dynamic JSP pages can be directly accessed from the outside, possibly resulting in severe internal errors. No /WEB-INF/dynamic
indexUri /home The URI which serves as the homepage/welcome page of the web application. When a user makes a request to the root of the webapp (the domain followed by the context path) without specifying a specific action URI, he is redirected to this URI. No /index