O'Reilly logo

Struts Kick Start by Kevin Bedell, James Turner

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

Passing Data to the View Using Attributes: Constants.java

In the earlier section on the Action class (HelloAction.java), you saw how the Action class passed between itself and the View components using the setAttribute() and getAttribute() methods of the request object. Now let’s look at this process in a bit more detail.

When you pass an object from the ActionClass to the View component (a JSP page) using the request.setAttribute(), you need to provide a name, or string identifier, that the JSP file can use to retrieve the object with. In Struts applications, a convention has been adopted for using a file named Constants.java to define these names. Listing 3.6 contains the Constants.java file for the HelloWorld! application.

Listing 3.6. ...

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