J3 Limited
List System Properties Page


In the previous section a basic web application was created and tested to encure that all the necessary components are present and configured correctly.

In this section a Struts page that lists system properties is developed and run.

Edit struts-config.xml

The struts-config.xml is edited as follows:

<?xml version="1.0" encoding="ISO-8859-1" ?>
<!DOCTYPE struts-config PUBLIC
"-//Apache Software Foundation//DTD Struts Configuration 1.3//EN"

<form-beans />
<global-exceptions />
<global-forwards >
<forward name="listProperties" path="/listProperties.jsp"/>
<message-resources parameter="com.j3ltd.messages.StrutsProject"/>


Edit index.jsp

The index.jsp file is updated to hold a hyperlink to the Struts action that is about to be added:

<%@ taglib uri="http://struts.apache.org/tags-html" prefix="html" %>
<%@ taglib uri="http://struts.apache.org/tags-bean" prefix="bean" %>
<title><bean:message key="indexTitle"/></title>
<h1><bean:message key="indexHeading"/></h1><br>
<html:link page="/listProperties.do"><bean:message key="indexListProperties"/></html:link>

the uri for the tag libraries is found by opening up the struts jar file struts-taglib-1.3.8.jar. It contains the tld files. For example, the file struts-html.tld, when opened in a text editor, contains the line "<uri>http://struts.apache.org/tags-html</uri>"

Create listProperties.jsp

A new jsp called listProperties.jsp is created, with the following content:

<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
<%@ taglib uri="http://struts.apache.org/tags-html" prefix="html" %>
<%@taglib uri="http://java.sun.com/jstl/core_rt" prefix="c" %>
<%@ taglib uri="http://struts.apache.org/tags-bean" prefix="bean" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" 
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title><bean:message key="listPropertiesTitle"/></title>
<h1><bean:message key="listPropertiesHeading"/></h1><br>
<table border="1">
         <th align="left">
            <bean:message key="listPropertiesNameHeader"/>
         <th align="left">
            <bean:message key="listPropertiesValueHeader"/>
         <c:when test="${empty systemProperties}">
               <td align="left" colspan="2">
                <bean:message key="listPropertiesNoProperties"/>
            <c:forEach items="${systemProperties}" var="aProperty">
                  <td align="left" valign="top">${aProperty.name}</td>
                  <td align="left" valign="top">${aProperty.value}  </td>

  • The JSTL core tag lib is used. The uri specified is "http://java.sun.com/jstl/core_rt". This was found by opening up the struts jar file standard-1.0.2.jar, and looking at the tld files' content.
  • For internationalized messages, the bean:message tag is used. JSTL has the fmt:message tag. In order to avoid repeating the message file name in web.xml, struts-config.xml and possibly the jsp's, the Struts bean tag has been used: the message file name is only present in struts-config.xml

Create The Messages File

The message file, which contains all the text that is displayed by the application, is created in the src folder (src\com\j3ltd\messages\StrutsProject.properties):

# index.jsp resources
indexTitle=Struts Project
indexHeading=This is the struts index page
indexListProperties=Display a list of the system properties 

# listProperties.jsp resources
listPropertiesTitle=List System Properties
listPropertiesHeading=System Property List
listPropertiesNameHeader=Property Name
listPropertiesValueHeader=Property Value
listPropertiesNoProperties=No system properties to list                          

Create Supporting Files (POJO, DAO)

A Java bean is created which holds a system property's name and value:

package com.j3ltd.bean;

public class PropertyBean {
	private String name;
	private String value;
	public String getName() {
		return name;
	public void setName(String name) {
		this.name = name;
	public String getValue() {
		return value;
	public void setValue(String value) {
		this.value = value;

A class to get the system properties into a list is created:

package com.j3ltd.dao;

import java.util.ArrayList;
import java.util.List;
import java.util.Properties;

import com.j3ltd.bean.PropertyBean;

public class StrutsProjectDao {
	public static List<PropertyBean> getPropertyList() {
		Properties systemProperties = System.getProperties();
		ArrayList propertyBeans = new ArrayList(systemProperties.size());
		for (Object aKey : systemProperties.keySet()) {
			Object aValue = systemProperties.get(aKey);
			PropertyBean aProperty = new PropertyBean();
		return propertyBeans;

Create An Action Controller

Finally, the Struts Action controller class is written:

package com.j3ltd.controller;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.struts.action.Action;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;

import com.j3ltd.factory.StrutsProjectDao;

public class ListPropertiesAction extends Action {
	public ActionForward execute(
			ActionMapping mapping,
			ActionForm form,
			HttpServletRequest request,
			HttpServletResponse response)
			throws Exception {
			return mapping.findForward("listProperties");

Run The Project

The project is launched in debug mode, and the index page is displayed, in Eclipse:


The hyperlink is clicked to display the listProperties.jsp:

property list

A Jar file of the project files can be downloaded here. The jar file's contents can be extracted using various opensource archive utilities, or using the JDK's jar command line tool.

In the next section facilities to edit system properties are added.


  Copyright © 2006 J3 Ltd Permission is granted to reproduce material on this page, on the condition that a reference to "WWW.J3Ltd.com" is given as the source of the material.