O'Reilly logo

Head First Servlets and JSP, 2nd Edition by Bert Bates, Bryan Basham, Kathy Sierra

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Yes! It’s Struts in a nutshell

Obviously this is an overview, and we’ve left out pretty much all of the details, but this is the basic idea behind the Struts framework. Let’s look at a few more details, starting with the fact that we’ve changed all the names...

image with no caption

Key Struts Components

Action Servlet - You’ll need only one of these per application.

Best of all, you don’t even have to write it, Struts provides it.

Form Beans - You’ll write one of these for each HTML form your app needs to process. They are Java beans, and once the Struts Action Servlet has called the setters on the form bean (to populate the bean with form parameters), it will call the bean’s validate() method. This is a great place to put data conversion and error handling logic.

Action Objects - Generally, an action maps to a single activity in a use-case. It has a call-back-like method called execute(), which is a great place to get the validated form params, and call model components. Think of the Action object as kind of a “servlet lite”.

struts-config.xml - This is the Struts-specific deployment descriptor. In it you’ll map: request URLs to Actions, Actions to Form beans, and Actions to views.

image with no caption

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required