struts-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Craig R. McClanahan" <>
Subject Re: Propper use of ActionServlets
Date Fri, 06 Oct 2000 20:14:11 GMT
I will throw in my thoughts ... I'm sure others will have their own.

Larry Kim wrote:

> Hi,
> I am developing a web app using the struts framework.  The application alows
> for viewing, creating, editing and deleting of data in a database.  My
> question is regarding the proper use of actionservlets.
> Is it better to have a separate action servlet for every different possible
> action, so in this case, have action servlets for View, Create, Edit and
> Delete, OR is it better to have say one or 2 action servlets that employ
> conditional logic to figure out what action is to be performed?

> having a separate actionservlets for every action results in relatively
> empty servlets,
> however the action.xml file is far easier to read.
> having only 2 uber-actionservlets results in fewer files, but the action.xml
> file is more
> difficult to follow since there are many action mappings mapped to the same
> action servlet.

Having a controller servlet per action seems to miss the whole point of having a
single controller, where you can make sure that common logic gets executed.
Also, each individual action.xml file might be easier to read (because it has
only one action), but you might now have hundreds of them (if you've got
hundreds of actions).  There's no way to read them all in one place.

I also don't see much value in having two action servlets, versus one.  The
Struts framework (and most others based on the same architectural idea) is set
up to scale nicely to apps having hundreds to thousands of actions -- because
the mappings are all looked up in hashtables, and the XML stuff is processed
only at the beginning, and so on.

A potential negative to a single all-encompassing action.xml file, though, is
how do you allow multiple developers to edit it?  Two solutions come to my mind
immediately -- there may well be others:

* In your development environment, divide the internal contents of the
  action.xml file into individual components (say, all of the actions that
  deal with a particular subset of your overall functionality).  Then, in the
  build scripts for your app, use something like the Unix "cat" command
  to glue them all together into a single action.xml file.

* I haven't tried this, but the same situation comes up with build.xml files
  if you use Ant as your build tool (as I do for the Struts framework itself).
  Apparently, you can ask the XML parser to do what amounts to "include"
  commands at runtime, so your top-level action.xml might look like this:

        <?xml version="1.0">

        <!DOCTYPE part1 [
            <!ENTITY Part1 SYSTEM "file:./part1.xml">

        <!DOCTYPE part2 [
            <!ENTITY Part2 SYSTEM "file:./part2.xml">





    and the parser would assemble the entire file when Struts reads it
    at initialization time.

> is there any other pros/cons i have missed?
> very sincerely,
> Larry Kim

Craig McClanahan

See you at ApacheCon Europe <>!
Session VS01 (23-Oct 13h00-17h00):  Sun Technical Briefing
Session T06  (24-Oct 14h00-15h00):  Migrating Apache JServ
                                    Applications to Tomcat

View raw message