I've just been learning the basics of Struts, and am thinking of suggesting its use where I work - we currently use a couple of inhouse 'frameworks' for templating HTML and loading/saving from database but I think Struts might help simplify our JSPs. Before suggesting it I thought I'd try summarising how it works to make sure I understood, and also try it out to see what potential problems might be. Since I'd gone to the effort of summarising it, I thought I'd post it here for any comments on what I've got wrong, and hopefully to help other newbies.
So heres my Quick Summary of Struts :
Struts is a framework for the development of web applications using JSPs.
A Servlet (class "org.apache.struts.action.ActionServlet") is configured in web.xml, with parameters specifying things like where the struts XML config file is. Also in web.xml this servlet is normally mapped to URL "/do/*".
JSPs are written using custom tags provided by Struts (obviously standard JSP code will work to, but the tatg help simplify the JSPs). Forms in JSPs map to Struts actions.
For each action (e.g. login, create user, submit score , etc. ) an Action class needs to be created extending "org.apache.struts.action.Action" and implementing the following function:
Also for each action a form class is created by extending ActionForm, this is a bean with getters and setters corresponding to the fields in the form on the JSP and a validate function which provides oportunity to check for missing fields, or format of data entered etc.
Signature of validate method:
In the struts XML config file, forms and actions are configured.
The "Action" Servlet acts as the controller in the MVC pattern, the validate function of appropriate form class is called (if configured), if validation is OK then the approriate action object is used to handle the request via the execute method, otherwise the JSP with the form on is redisplayed with errors shown. The execute method interfaces with the "Model" - the main "business logic" of the application which probably interfaces with a relational database to do whatever it needs to do. Any errors encountered are added to an ActionErrors object and saved in the request, so they can be displayed.
Then an Action forward object that will be returned needs to be created based on the results of the action and config in the Struts Xml file - e.g. forward to display a list of users, or to display errors. The Struts framework then forwards the request to the appropriate URL based on the Action Forward object - normally a JSP, which acts as the "View" in the MVC, possibly displaying errors stored in the request.
This description has just covered the normal core functionality, Struts provides other stuff, and can also be configured to behave differently.
======================= End of summary Problems With Struts
As I've only just started experimenting with Struts its a bit early to be sure of what the problems are, but anyway here goes: Properties file will quickly get very big and unmanageable.Language selection using properties file :- Ideally I'd like to make language selection dynamically by user, not by swapping properties files. Perhaps I'm missing something.Yet another thing for developers to have to learn - not sure about this, its probably easier to learn Struts than work on a JSPs which submit to them selves with loads of Java scriptletsIts too generic/complex/heavyweight - notice a few posts suggesting this, but again, not sure that I agree
OK - Thats it any comments welcome!
[ March 25, 2004: Message edited by: Mikey Warren ]