Playing with Struts Day 1 June 27, 2005Posted by javafoo in javanotes, struts basic.
Ok, so finally after looking at much examples, I thought I had a basic idea and this was too trivial to actually go about trying. But today out of sheer boredem, I exported the struts-blank.war into Tomcat and got hacking at it. So here goes my tryst with struts:
- 2:15 PM Ok then, I edit struts-config.xml: create a simple logonForm extending DynActionForm, add action logon, map the action to logonForm and a LogonAction class, that I will code in a bit.
- 2:30 PM I create the jsps using the tags.
- 2:40 I get interrupted, they want me to do some work actually.
- 3:30 PM Ok where was I? Right the jsps; I write a simple action class: LogonAction, in which I check the username and password against hard-coded values and if they match, forward the page to success, if not forward to failure.
- 3:35 PM I am all compiled and ready to go, I fire up Tomcat and go to the logon page.
- 3:40PM Hurrah! I can actually see the logon page, I hit submit, the page goes to logon.do, but empty page.
- 3:45 PM I think there might be something wrong in the Action class, so I comment the very cryptic username, password checking logic and just forward the page to success. I fire up Tomcat again.
- Fast Forward: a few iterations, debugs, logs and System.out.println later:
- 4:30 PM Still no luck, also anything I log or write to sysout does not show up in the logs, so probably the action calss is not even getting invoked.
- 4:45 PM I tear out my hair, google for “struts action empty page”, there is something about previous Action API requiring you to implement perform and current ones needing you to implement execute.
- 5:00 PM So, sure enough I am impelmenting perform, I just change this to execute and try again, Hallelujah!, I am strutting away to glory.
Moral of the story when in “Action”, “execute”, do not “perform”.
So much for struts.