Accomplished a few things today … I finally figured out how to create an externalized mapping of commands to classes. I was reading a chapter in the book JavaServer Pages by Oreilly. They described a popular technique of creating an Action Interface and then extending this interface to give you a mapping of actions to class names. This is the code snippet they show:
So I made an action interface, made an action class (has to be serializable) and tried writing this Hashtable to a file with ObjectOutputStream and then I viewed it. The file was in binary format and wouldn’t be maintainable because I need a flat text file that I can easily edit. My goal is to have a controller that I don’t have to touch when I add functionality. Something maintainable. I realized that this method might be good for writing objects to files, but wouldn’t help me here.
So then I tried this:
And all I have to have in /tmp/testme.txt is the following line: post = net.fuzzylemon.acronym.action.PostAction.
Here’s my action interface:
And here’s my PostAction class:
Of course, all this still needs to be cleaned up and implemented in a servlet, but it’s progress.
I am going to document my progress through a personal challenge so to help others and myself learn about steps A-Z in creating a web app from scratch.
The Acronym Challenge is going to be a posting game (I use this term loosely) where an acronym will be posted and people submit entries that match the acronym. For example, TCP = tangy chocolate popsicles. Then the entries can be voted on. A set number of top scoring entries will be displayed, etc, etc. The entire system will be anonymous to start with and may or may not incorporate login functionality. I want it to be easy to use.
It’s going to be written in Java because I want to learn more about J2EE and Java in general. My goal is to write it from scratch without using frameworks even though Struts looks very useful. I’m using the Eclipse IDE and Tomcat 4.1.x as my web app server (more on that later). Database support is going to have to be limited to MySQL because that’s all I know. Eclipse does the packaging a deployment for me with the Lomboz J2EE plugin. Eclipse also takes care of a lot of the Javadoc work. I’m sparsely using CVS to track changes and keep a backup copy even though I’m the only one on my team. :)
Finally got a useful action map coded. Before, the controller was just simply printing Strings. Now, Classes are being instantiated from a Properties file and the Action interface is working as it should. The latest version of the Controller is posted.