Static Parameter, Static Parameter in Struts 2, Struts 2 Static Parameter

In this tutorial you will learn about Static parameter of struts2 framework

Ads

Tutorials   
Login form in Struts2 version 2.3.16 Struts 2 Login Application Struts 2 Hello World Annotation Example Struts 2 Tutorial: Easy steps to learn Struts 2 Struts2 Application in Eclipse: Running the application in Eclipse IDE Struts 2 Hello World Application using Eclipse Interceptors in Struts 2 Struts 2 Action Tag Struts 2 in Agile Development Environment Struts 2 UI Tags Generic Tags Creating own Interceptor What are Interceptors in Struts 2 and how do they work? Results Value Stack / OGNL Action in Struts 2 Framework Struts 2 Interceptors Struts 2.3.15.1 Maven - How to use Maven dependency of Struts 2.3.15.1? Download Struts 2.3.15.1 How Struts 2 Framework works? Architecture of Struts 2 Framework Features and Enhancements in Struts 2.3.15.1 Struts 2 Tutorials - Struts version 2.3.15.1 Struts Flow Diagram Step By Step Struts Tutorial Struts 2 Login Form Example Struts 2 Hello World Example Introduction to Struts 2 Framework Downloading and Installing Struts 2.3.8 Struts 2.3.8 released with new features Struts 2.3.8 Tutorials and Examples Subset Tag Actionerror Tag Struts 2 Autocompleter,Struts 2 Autocomplete Generator Tag Struts 2 Application Struts 2 zero configuration,Struts 2 zero configuration Example Static Parameter, Static Parameter in Struts 2, Struts 2 Static Parameter Pagination Example Struts 2.2.1 Title Struts2 ElseIf Tag Example Struts2 Else Tag Example Struts2 If,Else,ElseIf Tag Example Struts2 tag refrences and Example How to download, compile and test the tutorials using ant. Struts 2.1.8 Login Form Struts 2.1.8 Hello World Example Download Struts 2.1.8, Downloading and installing Struts 2.1.8 Showcase application
Ads
<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>
  <result>/pages/staticparameter/showparamerts.jsp</result>
</action>

Create a simple JavaBean StaticParameter.java 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 (StaticParameter.java) through the 'ant' command. 

StaticParameter.java

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.  

showparameters.jsp

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

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:

Advertisements

Ads
Share on Google+Share on Google+

Static Parameter, Static Parameter in Struts 2, Struts 2 Static Parameter

Posted on: April 18, 2011 If you enjoyed this post then why not add us on Google+? Add us to your Circles

Advertisements

 

Discuss: Static Parameter, Static Parameter in Struts 2, Struts 2 Static Parameter  

Post your Comment


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

Ads

 

Ads