Home Struts Struts Struts2.2.1 Tags Access value of array using OGNL in struts2.

Ask Questions?

View Latest Questions


 
 

Access value of array using OGNL in struts2.
Posted on: January 24, 2011 at 12:00 AM
Advertisement
Here, you will see how to access value of array in struts2 using OGNL.

Access value of array using OGNL in struts2.

Here, you will see how to access value of  array in struts2 using OGNL.

 1-index.jsp

<%@taglib uri="/struts-tags" prefix="s"%><html>

<head>

<title>OGNL_Example</title>

</head>

<body><h1>OGNL_Example</h1><hr>

<a href="ognlAction.action">OGNL_Example</a>

</body>

</html>

3_ OGNLAction .java   (Action class)

package roseindia.action;

import java.util.ArrayList;

import java.util.List;

import com.opensymphony.xwork2.ActionSupport;

ublic class OGNLAction extends ActionSupport{

private List<String> name=new ArrayList<String>();

{

name.add("Bharat");

name.add("Avnish");

name.add("Gyan");

name.add("Ankit");

}

public String execute() throws Exception {

return SUCCESS;

}

public List<String> getName() {

return name;

}

public void setName(List<String> name) {

this.name = name;

}

}

5_ struts.xml

<struts>

<constant name="struts.devMode" value="false" />

<package name="roseindia" extends="struts-default">

<action name="ognlJsp">

<result>OGNLJsp.jsp</result>

</action>

<action name="ognlAction" class="roseindia.action.OGNLAction">

<result name="success">display.jsp</result>

</action>

</package>

</struts>

5_ struts.xml

<%@taglib uri="/struts-tags" prefix="s" %>

<html>

<head>

<title>OGNL_Example</title>

</head>

<body><h1>OGNL_Example</h1><hr>

Size of list : <s:property value="name.size"/><br/>

<p> access data of list.</p><br/>

name[3] : <s:property value="name[3]"/><br/>

name[2] : <s:property value="name[2]"/><br/>

name[1] : <s:property value="name[1]"/><br/>

name[0] : <s:property value="name[0]"/><br/>

Value array list : <s:property value="name"/>

</body>

</html

Output

Download Source Code

Related Tags for Access value of array using OGNL in struts2.:


DMCA.com