Static Parameter

In this section, we will develop a simple application to access the static parameter.



Static Parameter


In this section, we will develop a simple application to access the static parameters. We will use a JavaBean to set and get the static parameters. Each static parameter has a value.  

Description :

Develop a JavaBean with three properties (Static Parameters) of string type ( parameter1,parameter2, parameter3 ). Define three JavaBean properties and add their corresponding values in the action mapping (in the application's struts.xml ). Set the name(s) and value(s) as shown below:

code snippet from

<action name="StaticParameter" class="net.roseindia.StaticParameter">
  <param name="pramater1">Value 1</param>
  <param name="pramater2">Value 2</param>
  <param name="pramater3">Value 3</param>

Create a simple JavaBean in the "struts2tutorial\WEB-INF\src\java\net\roseindia" directory. Here  the "StaticParameter" class extends the ActionSupport class. It sets and gets the three static parameters by using the setParameter1(), setParameter2(), setParameter3() and getParameter1(), getParameter2(), getParameter3() methods. 

Now compile the JavaBean ( through the 'ant' command.

package net.roseindia;
import com.opensymphony.xwork2.ActionSupport;
import java.util.Date;

public  class StaticParameter  extends ActionSupport {

  private String pramater1;
  private String pramater2;
  private String pramater3;
  public String execute() throws Exception {
  return SUCCESS;

  public String getPramater1() {
  return pramater1;

  public void setPramater1(String pramater1) {
  this.pramater1 = pramater1;

  public String getPramater2() {
  return pramater2;

  public void setPramater2(String pramater2) {
  this.pramater2 = pramater2;

  public String getPramater3() {
  return pramater3;

  public void setPramater3(String pramater3) {
  this.pramater3 = pramater3;


Create a jsp page (showparameters.jsp) to view the static parameters.  


<%taglib prefix="s" uri="/struts-tags" %>
  <title>Static Parameter Example!</title>
  <h1>Static Parameter</h1>
  <table border="1" width="25%" bgcolor="#ffffcc">
  <td width="25%"><b>Key</b></td>
  <td width="25%"><b>Value</b></td>
  <td width="25%">pramater1</td>
  <td width="25%"><s:property value="pramater1" /></td>
  <td width="25%">pramater2</td>
  <td width="25%"><s:property value="pramater2" /></td>
  <td width="25%">pramater3</td>
  <td width="25%"><s:property value="pramater3" /></td>

Open web browser and give request as http://localhost:8080/struts2tutorial/roseindia/StaticParameter.action. It displays a table that contains three static parameters in key-value format.

Output of this application:


Share on Google+Share on Google+

Static Parameter

Posted on: July 9, 2007 If you enjoyed this post then why not add us on Google+? Add us to your Circles



Discuss: Static Parameter   View All Comments

Post your Comment

Your Name (*) :
Your Email :
Subject (*):
Your Comment (*):
  Reload Image