Using the Struts Framework to Develop a Message Board--Part I: Introduction
- Using the Struts Framework to Develop a Message Board--Part I: Introduction
- What You Will Need
In this series, we will explore a new, exciting application framework—the Apache Software Foundation's Struts framework in developing a Web-based message board. Like any Web-based message board, the message board allows users to post messages and replies, as well as view the other messages on the bulletin board.
Introducing the Struts Framework
The Struts framework is a part of the open source Apache Jakarta project, which can be used to develop Web applications with Java servlet and JSP technology. It facilitates application architectures based on the time-tested Model-View-Controller (MVC) paradigm.
The Struts framework provides Java classes, custom tag libraries, and servlets that address all of the components involved in the MVC architecture.
The model represents the entities involved in the Web dialogue. The model is implemented using Java classes that contain properties that represent the attributes of the entity.
In the message board application, for example, three discernable entities can be observed:
- A user who posts and views messages.
- A message being posted or viewed.
- The message board, which contains messages that a user can view. The users' replies are added to this repository as well.
The Struts framework provides an ActionForm class that you can use to extend and develop these model classes.
The view represents the user interface for the Web application. These are typically built using plain HTML for static content, and JSPs for developing dynamic content.
The Struts framework provides a set of custom tags that allows messages and the resulting pages to be truly internationalized. It also provides a custom tag library that allows interaction between the ActionForm and the form elements.
For this application, a set of JSPs need to be developed for the following purposes:
- Creating a new message to be posted to the message board
- Displaying a message in the message board
- Displaying the entire message board that can be browsed
- A help page to display errors and provide the user with navigational links for using the message board
In addition to the JSPs, you will need to define a resource bundle of messages, a properties file, for each locale in the internationalized application.
The controller is the glue that binds the input to the output. It is responsible for receiving the request, performing the necessary command, and delegating the request to the output page.
The Struts framework provides a generic servlet, ActionServlet, which acts as the controller. You will need to develop Action classes that perform the specific command.
You also need to specify a set of mappings, described in XML configuration files that are used by the ActionServlet class to match the input URI, a specific model class (an ActionForm class) to the output pages routed through a command (an Action class).