Home > Articles > Programming > Java

Using the Struts Framework to Develop a Message Board--Part 3: Developing the View Components for the Message Board

📄 Contents

  1. Using the Struts Framework to Develop a Message Board--Part 3: Developing the View Components for the Message Board
  2. Create the Output JSP That Displays a Message
  3. Creating a Help Page
  4. Creating the Localized Resource Bundles
  • Print
  • + Share This
In this seven-part series, Java expert Maneesh Sahu explores how to use Apache Software Foundation's Struts framework to develop a Web-based message board.
From the author of

The view components comprise the JSPs for the input forms and output pages. To internationalize text for the pages, you will also need to add entries for each internationalized resource in the properties file.

Create the Input JSP with the Form

The next step is to create the JSP containing the HTML form. Instead of using the HTML form elements, we will use the custom tag equivalents provided in the Struts framework, as shown in Listing 1. Using the custom tags is advantageous because the framework allows you to initialize the input fields with data using bean introspection that matches the ActionForm properties with form elements to equivalent names. The form tag's action attribute specifies a servlet-mapping action name: add.do. Part 4 of this series, "Developing the Controller for the Application" explains this more thoroughly. Part 4 also specifies the model class: Message, which is used to populate the form elements and the name of the variable in the session scope messageForm.

In addition to the Struts' form tags, the errors custom tag allows you to display the errors you encountered while validating the form.

To internationalize the text, such as the title in the output page, we will use the message tag that accepts the key of the actual message. The actual message is stored in the same properties file that contains the error messages.

Listing 1 message.jsp

<%@ taglib uri="/WEB-INF/struts.tld" prefix="struts" %>
    <title><struts:message key="message.title"/></title>
<struts:form action="add.do" name="messageForm" focus="subject"
    <struts:hidden property="parentId"/>
<table width="400">
<td><struts:message key="message.name"/></td>
<td><struts:text property="name" size="20"/></td>
<td><struts:message key="message.email"/></td>
<td><struts:text property="email" size="20"/></td>
<td><struts:message key="message.subject"/></td>
<td><struts:text property="subject" size="20"/></td>
<td valign="top"><struts:message key="message.body"/></td>
<td><struts:textarea property="body" rows="4"/></td>
    <struts:submit/> <struts:reset/>
  • + Share This
  • 🔖 Save To Your Account