Struts 2 find a particular list based on the index in struts 2. Sometimes the user needs value based on the index in struts 2 there are different ways to get value based on the index in struts2. 

Struts2 Get Value on Index base. Here writing a java struts program to get a list in struts based on an index. Getting a value from a list, based on the index in struts2 which we can use to fulfill our needs.

 
This is jsp code CountIncrement.jsp

	

Count in struts2

Count Increment

List value on Index[0] Base:

List Sturts2 set value Base:


After Adding This You have to Add mapping in Struts.xml.
Here I am Using struts2 XML for mapping you can use Mapping or Annotation.
This is struts.xml code.




    CountIncrement.jsp



This is SturtsAction class which contains CountIndexAction Constructor. In this Constructor, I have Set Static Values in ArrayList of CountIndexAction Class Constructor you can set by a call to Your Database.

	public class CountIndexAction  extends ActionSupport {
		private List<String> countryname = new ArrayList<String>();
		public List<String> getCountryname() {
		return countryname;
		}
		
		public void setCountryname(List<String> countryname) {
		this.countryname = countryname;
		}

		//constructor
		public CountIndexAction () {
		System.err.println("Country name");
		countryname.add("India");
		countryname.add("Indonesia");
		countryname.add("Iran");
		countryname.add("Australia");
		countryname.add("Afghanistan");
		countryname.add("Brazil");
		countryname.add("Colombia");
		countryname.add("China");
		countryname.add("Curacao");
		countryname.add("Denmark");
		countryname.add("Egypt");
		countryname.add("Others");
		}

	}


This is images of Increment In struts2 or Access value on index base in Struts2
Hitting this Count Increment it called to the action of struts2count which a CountIndexAction class Attached to it



Output


Post a Comment

Previous Post Next Post