<%@ page language="java" %> <%@ page import="com.maff.forum.*,com.maff.forum.jsp.*" %> <%@ page session="false" %> Slots User Guide - Software Reality <%@ include file="/include/body.txt" %> <%@ include file="/design/table-top.txt" %> <%@ include file="/design/title.txt" %> <%@ include file="/include/navbar.txt" %> <%@ include file="/include/storytable-top.txt" %> Slots Web Framework <%@ include file="/include/storytable-mid.txt" %>

Slots User Guide

<< Slots Central


What is Slots?

Slots is a templating framework for servlets and JSP. However, 'framework' isn't entirely accurate, unless you consider 2 class files a framework.

Yes, that's right, the entirety of Slots is 2 class files, the main controller servlet SlotServlet, and an extremely useful wrapper class that calls a page and returns its response in a string, SlotWrapper. The only other file needed is slots-config.properties, which defines your templates and page definitions.

Slots was created in order to give developers an easy to understand, easy to learn templating framework, where you don't have to buy several books, get a mortgage on a second brain, nor swear alegiance to a new coding religion. All the code is open source, and given the size of the code base (around 350 lines), only takes a few minutes to get your head around. I assume you understand basic Servlets and JSP, nothing else is needed. There is no concept of deploy, no need to stop/start the JSP engine, simply alter your JSPs or slots-config files, then refresh your browser. This leads to very rapid iterations, no 60 second deploys.


User Guide

Here is an example of a very simple slots-config:


That's all you need to start using slots. What we are saying here is that for any file we give to Slots, we will use pagetemplate.jsp as its template definition.

pagetemplate.jsp can be as simple as:


If I call /slot/test1.jsp it will invoke test1.jsp and insert its response into the request attribute slots_content, then invoke pagetemplate.jsp

In doing this, every page so invoked can be guaranteed to have the same layout and structure. Should I wish to change this global layout, all I have to do is alter pagetemplate.jsp

Now I'd imagine that this simple template would not be enough for your needs. For example you may wish to have configurable page titles.

In this case we might have pagetemplate become


Then change slots-config to say:

mybase=base=/pagetemplate.jsp,title="My Site:"

Then every page would have "My Site:" as a title. However how would we specify per page titles? Easy, just say:

/test1.jsp=title="Test 1 page"

We use the default template, as before, buit this time override the title slot for this page. We aren't limited to static strings and could easily say:


in order to delegate the page title to another jsp. I can even say


to have all files under /admin automatically take a custom value for title.

Should I wish to have more than one tempate, not uncommon, its as easy as


i.e. all pages under /admin get to use this admintemplate, and get a default title of "Admin".

I can even define a base as inheriting from another base e.g.


A common need in web based applications is to rename pages or otherwise refactor how things are handled in your workflow. In Slots this is easy:


By overriding the content slot I actually delegate page content to another page altogether. I can even supply mocked up contents for a page I have yet to fully define, e.g.

/test1.jsp=content="TODO: test 1"

For every slot you have in an entry, you get a "slot_slotname" entry in the request attributes with the value of that slot, either static string, or the response from another page.

e.g. if I say

/test2.jsp=title="Test 2 page",otherslot=/somethingelse.jsp

then when I call /slot/test2.jsp it will insert slot_title with "Test 2 page" and slot_otherslot with the response from /somethingelse.jsp. These will override any similarly named slots from the default base, if any.

test2.jsp will then be called, with all these values in the request attributes, to use or ignore as it sees fit. This response will then be inserted into slots_content, which then gets passed onto the default base jsp page, once again to use or ignore as it sees fit.


<< Slots Central

<< Software Reality Front Page


<%@ include file="/include/storytable-bot.txt" %> <%-- navbar2 --%> <%@ include file="/design/table-bot.txt" %>