• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Summary of Struts, by Struts newbie

 
Ranch Hand
Posts: 30
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
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 Struts 1.1 an alternative to creating a form class is to configure a dynamically generated form class, and also to employ client side javascript validation automatically generated from the config.
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 scriptlets
  • Its 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 ]
     
    Sheriff
    Posts: 17644
    300
    Mac Android IntelliJ IDE Eclipse IDE Spring Debian Java Ubuntu Linux
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    Seems like you've got a good handle on it. Couple of comments: while I have seen struts urls mapped with "/do/*", I think "*.do" is more common (Ted Husted says this in his book "Struts in Action"). Also, regarding language support, I'm not sure what exactly you mean by "swapping out" properties files but you can provide as many properties files as languages you want to support. They can all exist at the same time. You or your user simply need to specify the locale to use and Java will take care of the rest.
    Generic/complex/heavyweight? Well, I'd much rather have the plumbing already done for me than do it all over myself and still come up with something very similar yet less robust and feature-ladden.
     
    Mikey Warren
    Ranch Hand
    Posts: 30
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    Thanks for the reply.
    I was hoping that changing languages didn't mean just replacing the properties file with one for a different language - think I need to do a bit more reading up on that subject.
    Think I agree with you on the advantages of Struts, I was just interested in peoples opinions. It certainly seems preferable to what we've currently got which is JSPs with lots of Java code handling submits and presentation of data.
     
    Junilu Lacar
    Sheriff
    Posts: 17644
    300
    Mac Android IntelliJ IDE Eclipse IDE Spring Debian Java Ubuntu Linux
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator

    Originally posted by Mikey Warren:
    It certainly seems preferable to what we've currently got which is JSPs with lots of Java code handling submits and presentation of data.


    Ouch. Lots of scriptlets cause lots of headaches. Can't imagine anybody writing a non-trivial application that way and still keep whatever sanity they had in the first place...
     
    reply
      Bookmark Topic Watch Topic
    • New Topic