






Struts Survival Guide 113
Struts Survival Guide: Basics to Best Practices | |
author | Srikanth Shenoy, Nithin Mallya |
pages | 224 |
publisher | ObjectSource Publications |
rating | 8 |
reviewer | Wilson Fereira |
ISBN | 0974848808 |
summary | A short but valuable guide to the Jakarta Struts framework. |
Even before I started reading the book, the fact that stood out most was its pricing. The book costs $14.95, and is great buy for everybody and especially students. The book is light -- just 224 pages -- and is an easy read. The authors' style is neither dry nor humorous, but very convincing and developer friendly. Bottom line: It does not put you to sleep.
There are two aspects to any framework: the first aspect is the features of the framework itself; the second aspect is how easy it is to use them effectively. This book does justice to both aspects of Struts. It covers enough framework features to justify its title, starting from bare bones and then slowly guiding you to more advanced topics. In addition, there are chapters dedicated to dealing with variety of scenarios in web applications where Struts can be used to solve the problems effectively. This is the area where the book shines.
Chapter-wise reviews
The book starts off with an excellent introduction to MVC and how Struts fits into MVC. It then explains the basics of Struts very well and develops a hands-on application in Struts in the first three chapters.The fun starts from Chapter 4 onwards. Chapter 4 covers advanced Struts concepts and presents some interesting ideas about Struts Action design. Of particular interest are the coverage of how to protect your JSPs from direct access, using SwitchAction to navigate between multiple Struts modules. The different mechanisms of Action chaining and scenarios where Action chaining is not recommended is also an enlightening read. One of the controversial points in the book is that author discourages you from using XDoclet and explains why XDoclet is not a great idea with Struts.
Chapter 5 covers the validation in Struts. It is the shortest write up on Validation I have ever read and yet it beautifully explains the Commons Validator and its integration with Struts. In the context of validation, the author also explains when to use DynaActionForm and its derivatives and when not to.
Chapter 6 deals with Struts Tags. Reading this chapter was such a refresher. Other books on Struts have bored me with details of each attribute of each tag in Struts. I find this approach non-intuitive since that information is supposed to be a cross-reference and available on Struts web site anyway. Not so with this book. This book takes the approach of explaining the basic tags by example. In chapter 6, the author dives straight into practical aspects of building web applications with Struts. One of the very first illustration is why and how to modify BaseTag (the one that renders ) to suit the real life deployment scenarios. Next the chapter takes up one of the serious issues with check boxes regarding their state and provides a solution. The chapter provides technique for seamlessly integrating JavaScript validations with Struts validation. A lot of Struts web application that we develop do not use plain buttons. Instead image buttons are used. Perhaps the author was very aware of this fact and the lack of support for image based form submissions in Struts. That is why the chapter and the book has frequent references and solutions for dealing with Image buttons. It all starts in this chapter with a great introduction and some classes that make the form submission on the JSP transparent to the Action classes.
The Chapter 6 provides little details on the Struts Bean tag library except for dealing with multiple resource bundles and some design tips. Perhaps the reason is that the bean tags are so straight forward and covered well in the Struts web site. Another highlight of the chapter is a short yet great coverage of JSTL as a background for Struts-EL. The JSTL is introduced in the context of Struts Logic tags as a solution to deal with convoluted and and confusing nested tags. The section on Struts-EL is really short and could have been more.
The creme la creme of Chapter 6 is the section on dealing with List Forms. Sometimes you often have to deal with Forms with collection, edit the collection or delete the collection. Developers are confused on this topic as is evident from the postings in Struts mailing lists. The author does a great job of resolving the mystery surrounding editable collections in Forms. The author also does a great job of integrating the Pager Taglib from JSPTags.com with Struts and how a high performance page traversal mechanism can be set up based on the ValueListIterator pattern (Core J2EE Pattern) and database specific mechanisms.
Chapter 7 is a very decent way to learn Tiles. Tiles can be very confusing due to its capability to achieve the same thing in numerous ways. The author sticks to just one approach of using Tiles with Struts and defends why that is the best approach. The pros of this approach are there are confusions and the learning curve with Tiles is flattened. Coverage of Tiles Controller is missing and is desirable.
Chapter 9 on Exception handling in Struts deserves some mention. It is one of the best exception handling chapters I have ever read. Most other books on Struts limit their exception chapter to explaining differences between Checked v/s Unchecked exceptions and telling how the tags work in the struts-config.xml. The coverage of Exception handling in this book alone is worth the price of the book. It provides a solid framework to handle Exceptions in Struts, log them in a centralized manner and report and alert in a production environment.
Chapter 10 is for folks who want to customize Struts and reap its benefits in design and development of production systems. It presents four examples of how Struts can be effectively customized. The best among them was how to how to handle duplicate form submissions in a generic manner. We all have to deal with duplicate form submissions in daily life and handle them on use case basis by using the Synchronizer tokens. The technique illustrated here no doubt relies on the Sync token but uses it a very ingenious manner, presents a generic Action class. I liked this technique. Other techniques I liked are that the chapter provides a Dispatch Action like functionality for Image based form submission. The DispatchAction in Struts is great, unfortunately I can use it only under certain restrictions. One of them is that the all of the buttons have to have the same name. This technique removes that restriction and opens a world of possibilities for designing cleaner applications while providing enhanced user experience.
If there is a feature in Struts which is not the best way to attack a problem, this book tells you that. The chapters are also interspersed with design tips for designing your Struts application better. In summary, this is a pragmatic Struts book and a highly recommended read for developers and architects already familiar with Struts. You will certainly pick up quite a bit of Struts tricks that will help you design better Struts applications. If you architect, design and develop Struts based applications for your living, do yourself a favor - Go buy this book. Even if you don't know Struts, you can learn it fast with this book. The only requirement is that you should already know the basics of how to develop J2EE web applications.
You can purchase Struts Survival Guide: Basics to Best Practices from bn.com. Slashdot welcomes readers' book reviews -- to see your own review here, read the book review guidelines, then visit the submission page.
Re:struts is a pig (Score:5, Funny)
MVC development is convoluted and confusing, therefore it is slow and memory hoggish.
Re:struts is a pig (Score:1, Interesting)
Re:struts is a pig (Score:2)
Re:struts is a pig (Score:1, Interesting)
How do JavaServer Faces compare? Anyone use them for a web application yet?
Re:struts is a pig (Score:1)
Haven't built anything with them yet, but I've been throwing around the buzzword for a few weeks now.
Re:struts is a pig (Score:5, Interesting)
You have a few approaches you can do in these webapps. You can stick to JSP and Servlets. JSP's biggest downside: mixing Java code and markup together is messy and difficult to maintain. For a small scale site, this works out just fine.
One other option: Struts + Velocity. I opted for this approach in a large scale app I just wrote. It's not any slower than JSP, and the code is amazingly maintainable. The learning curve for new developers is kind of steep, but once they get used to it, they love it. xdoclet makes the job of maintaining the struts-config.xml pretty painless. Even if you don't want to use xdoclet, it's a pretty simple xml file.
There are other options also, TurboM2, Cocoon, etc. Struts just happened to fit what I was doing best.
Re:struts is a pig (Score:2, Insightful)
That's why you create/use taglibs! You should never ever ever have java code exposed in a modern JSP page.
Re:struts is a pig -- downside?????? (Score:1)
i maintain a very large struts application and struts has made everything maintainable.
Re:struts is a pig -- downside?????? (Score:2, Interesting)
For instance;
If you have a page with a table of 34983 rows, and you want to split them ("go to next 100 results") in chunks and you created your page with all those fancy framework you have to change stuff in different-files, you have to create a new 'tag' and perhaps you have to "deploy" or what-ever....It's just not maintainable.
But say you wanted to do that several times over different tables with different size results. If you embed a java for loop in your JSP to accomplish this, you have to basic
Re:struts is a pig -- downside?????? (Score:1)
In this case, you are not tagging the for loop. You are tagging a specific browsing behavior(view N things at a time). And even if it were a simple for loop, using tags instead of scriptlets exposes iteration variables that other tags might want to use whereas you cannot easily get at local scriptlet variables.
My point is tags are a good thing and should be used when possible. Scriptlets are the main reason people say "JSP sucks cause you can still embed Java in your HTML". Tags encourage reuse. Scri
Struts + Velocity (Score:3, Interesting)
Velocity also excels at being a general purpose templating language - sure, JSP Expression Language gives you some of what Velocity does, but you can use Velocity to process any text, anywhere in a Java application.
Re:struts is a pig (Score:2)
better survival guide (Score:3, Informative)
See also: "Spring" (Score:3, Interesting)
I have having trouble understanding Struts (Score:4, Interesting)
Does it include a 'Pronunciation' chapter? (Score:5, Funny)
One thing that I'd be sure to look for in a Struts book is a section on how to correctly use the word Struts in a sentence of English language.
The issue here is that in some respects, 'Struts' is a singular noun referring to a framework - yet it ends with an 's' tricking many English-As-A-Second-Language-IT-Professionals into thinking that they need to apply rules of plural nouns. In extreme cases, I've heard people take the liberty of removing the 's' completely! as in:
"We will update the Action class of the Strut."
Re:Does it include a 'Pronunciation' chapter? (Score:2)
Re:Does it include a 'Pronunciation' chapter? (Score:2)
Re:Does it include a 'Pronunciation' chapter? (Score:2, Funny)
Maypole (Score:4, Interesting)
Also, while I'm thinking of it, does anyone know of a decent Python-based MVC?
Re:Maypole (Score:3, Insightful)
The rule of today's software development industry is that everything but Java sucks unless you're writing device-drivers. Once you learn how to at least pay that rule lip service in your job interviews you'll have a career's worth of work.
Re:Maypole (Score:1)
Most of the Struts benefits come from the taglib that maps object to html tag.
Re:Maypole (Score:2)
Am I the only one... (Score:5, Funny)
Sluts Survival Guide
DIY (Score:1)
Here a quick tip for a simple cluster. Use JMS or another queued message pool. Start as many servers as you need, and let each message be handled by whichever server is available. I was doing this in java in '97 and I still haven't seen a framework that beats it in performance, ease of use, or versatility.
Re:DIY (Score:4, Insightful)
If you really think it's easier to write your own Struts than use the one that's already written...well...either you are writing extremely simple apps or you are some kind of super-coder. There is a reason people don't all write their own version of Linux...
Re:DIY (Score:1)
Re:DIY (Score:2)
Re:DIY (Score:3, Interesting)
The arrogance!
There are major flaws with this line of thinking. I just started a new job where the developer I replaced shared your philosophy. It was a disaster. He wrote a half-assed persistent object model tied heavily to our application and MySql. Now that he's gone:
* Nobody can update his code on schema changes
* The code has bu
Re:DIY (Score:1)
But you repeat yourself!
Seriously, you folks who are so infatuated with ad-hoc halfassed hierarchical databases (sorry, "persistent object models") should take your own damn advice about "reinventing the wheel" and try using relational database management systems.
Too complicated? (Score:4, Insightful)
Re:Too complicated? (Score:3, Insightful)
I've come to the conclusion that there really is no need to use a language other than Python or Java unless you have to.
I can't understand my own Perl code after 3 months of not touching it.
C/C++ code breaks every time a library changes from a service pack on windows or an update on Linux. You can't leave C/C++ code untouched and expect it to run 6 months later.
ASP
Re:Too complicated? (Score:1)
Re:Too complicated? (Score:2)
If you are a fan of coldfusion, you can do the same thing in Java: the JSP standard tag libraries have all the same functionality and the EL (expression language) version allows run-time interpreted code to be embedded. The advantage of JSP is that, unlike cold fusion, it rea
Re:Too complicated? (Score:1)
Re:Too complicated? (Score:2)
Check out spring... (Score:5, Informative)
A framework I am working with currently is spring [springframework.org].
Spring is a superb framework for Java development and includes a pretty impressive MVC web toolkit as well as many other tools and features. The AOP stuff is very nice and the whole inversion of control/dependancy injection implementation simplifies code drastically.
Ive used quite a few different frameworks, but so far... this one is my favourite.
Re:Check out spring... (Score:4, Informative)
I've tried using Struts a few times, but it kept failing my 30 minute rule. (30 minutes to at least get some demo going other than "Hello World") Whereas I had the same idea of a demo going in Spring in about 15 minutes, on the first try.
I think Spring's advantage is it's IoC style of configuration and it's use of POJOs instead of the Struts style of extending one of their classes for everything.
Re:Check out spring... (Score:2)
just say no to struts (Score:2, Informative)
STRUTS is the ... (Score:4, Insightful)
Poor Man's WebObjects.
MVC for J2EE via WOF is what you want, but if you want Linux than one can see the popularity of Struts and other MVC frameworks on none Apple supported platforms.
Apache Cocoon2 Frameworks are much more interesting than Struts, personally.
Struts & WebObjects? (Score:4, Informative)
Fundamentally, Struts is a refactoring of the basic servlet API, but is still intrinsically operation-based (as are pure servlets).
WebObjects, and it's thematic successor Tapestry [apache.org] are component based approaches, an entirely different mindset. I created Tapestry and I have about two years of Struts experience ... Struts is a straight-jacket. Component frameworks offer incredible advantages in terms of clarity and developer productivity. Struts offers very, very little except a slew of books that have the daunting task of explaining in detail something that should be (was intended to be) very simple.
asp.net better than struts (Score:1, Interesting)
Struts rocks! (Score:1, Informative)
I stopped using struts, jsps, etc.... (Score:2)
I haven't looked back since.
To sum echo up:
Write web applications using a swing like API.
Book camparison (Score:1)
If so how do the two compare - is either one better than the other?
Struts is great but.... (Score:5, Informative)
http://java.sun.com/j2ee/javaserverfaces/
This is the framework that is being adopted by all major java IDE designers: NetBeans, Borland, Oracle etc. Fortunately, its not difficult to integrate struts and JSF, but for newer projects, JSF makes sense. It has an advantage in that the GUI doesn't have to be web pages - you will be able to 'plug in' WAP, Swing etc.
Re:Struts is great but.... (Score:5, Informative)
Re:Velocity (Score:2)
Re:Struts is great but.... (Score:3, Informative)
This is completely wrong. JSF is a total replacement for struts at all levels: model, view and controller. The JSP aspect of JSF is only one implementation of the presentation layer of JSF, and the reference implementation of JSF includes a JSP taglib front-end. One of the big advances of JSF is that it can in principle render all sorts of interfaces: WAP, XML, Swing, SWT, yet the underlying Java code and
No, JSF does replace struts (Score:2)
A direct quote from the author of struts:
"JSF provides functionality that overlaps that
of Struts (my misconception was that JSF was strictly a UI component
XWork / WebWork? (Score:3, Interesting)
Some have mentionned Spring, and I'd love it if anyone here could tell me how that compares to Struts, especially if they tried OpenSymphony's XWork or Webwork.
Any recommendations?
Re:No please... (Score:2, Funny)
"Struts is such a big over-engineered pile of shit."
I was going to mod this Insightful, but then thought, nah. You see, it doesn't go quite far enough. I've used Struts, once, and that was once too many. Repeat after me, children:
Struts is the festering soiled nappy of the bastard spawn of Satan.
Ugh. Now wash your mouths out with soap.
Re:No please... (Score:5, Informative)
Compared to what? Pure JSP? Maybe if you have like two pages total, but if you have any more than that you'll discover that:
If you set out to solve these problems, you'll inevitably end up at struts. It may do other things (don't know; I haven't ventured in that deeply), but it does these in about as simple a way as anyone could.
I challenge you to find any significant amount of redundant code in a project of mine that uses struts: mb. Description here [slamb.org], browse the code here [slamb.org]. There's not a lot of code there, and struts is largely responsible.
Internally, struts may be hugely overengineered...but I, as a user, don't care. It helps me keep my applications more terse and well-organized. (Much more maintainable than what I wrote before.)
Re:No please... (Score:2)
I looked at your code. It looked good. But what kind of real-world Struts stuff have you done, instead of just FOSS messageboards that you put together in your spare time? When you're dealing with real-world constraints like time, money, and requirements from non-technical users, Struts works against you at every turn.
Re:No please... (Score:1)
a well written struts app is very easy to find your way around, especially if you use a good ide.
Re:No please... (Score:3, Insightful)
Thank you. :)
But what kind of real-world Struts stuff have you done, instead of just FOSS messageboards that you put together in your spare time? When you're dealing with real-world constraints like time, money, and requirements from non-technical users, Struts works against you at every turn.
Never used struts at work. But it sounds like what you're really saying is that struts forces you to design a little, rather than just pumping out X lines of code/hour to me
Re:No please... (Score:2)
The problem is when management hears "Struts" and thinks "oooh, shiny" and then they make you use it without giving you time to use it right. Even though that's the wrong way to do it, that's reality. You rarely ever have enough time to do something right in the professional world, so anything that requires even more time is counterproductive.
Re:No please... (Score:3, Interesting)
Any basic Model 2 architecture implementation with some custom tags (e.g. from JSTL) and a template set.
If you want "event driven" it should be built-in from the start, like with ASP.Net's "code behind" logic.
(Short summary of Model 2 architecture: A "front controller" servlet which dispatches to JSPs based on state. Preferrably via a template that does includes for the selected content. All JSPs are "hidden" under WEB-INF to prohibit direct access from the outside. Optinal: Lower layer
Re:No please... (Score:2)
How is struts not that? I tend to use it as something that does just what you've described, plus the validator bit for the HTML forms. There may be additional parts of it that do other things, but they're clearly not necessary because I'm not using
Re:No please... (Score:2)
I am now embarking on a second app built on the technology of the first one. I spent the last 2 months rewriting much of the JSP side of things, having finally learned how to do things the right way.
I feel the biggest hole to fill in the literature is the tag libraries. I nearly killed myself learning how to properly
Re:No please... (Score:1, Informative)
There's lots of MVC jibba jabba from Struts foo's, but you don't need Struts for MVC, and using Struts means you have to put up with its many questionable design choices:
1. Singleton Actions.
I've read that this was due to performance, but that seems rather silly. If instantiating a form bean and populating it via reflection is acceptable, why is creating an instance of an Action a problem?
2. Decoupling Actions and Form beans.
Frankly, the seperation of Action (behavior)
Re:No please... (Score:2)
I've read that this was due to performance, but that seems rather silly. If instantiating a form bean and populating it via reflection is acceptable, why is creating an instance of an Action a problem?
Let me ask that the other way: what benefit would there be to a different structure? I have not heard those performance arguments (and they do sound suspect), but I don't see any reason to change.
2. Decoupling Actions and Form beans.
Frankly, the seperation of Action (behavior) and