TestController.java

@RequestMapping(value="/Control2/{personId}")		
public String TestMe(@PathVariable("personId") Long personIdVal)
{
  System.out.println(personIdVal);
  return "hello";
}

Input

http://localhost:8089/Test2/Control1/Control2/152

Output

152

For setting the Bean value in struts-config.xml we should use the form-beans tag.The form-beans tag might contain any number of bean property defined within form-bean as below.

Defining a Simple Bean Property

<form-beans>
 <form-bean name="userBean" type="org.apache.struts.action.DynaActionForm">
   <form-property name="userName" initial="This is Bean Value" type="java.lang.String" />	
 </form-bean>
</form-beans>

In the above code I am creating a userBean and setting its value is initialized to This is Bean Value.

Now in the action mapping part of the struts-config.xml I am going to map the above created bean to path as said below

<action-mappings>
 <action path="/showBeanValue" type="org.apache.struts.actions.ForwardAction" parameter="/showBeanValue.jsp"/>				
 <action name="userBean" path="/Login" />		
</action-mappings>

In the first line I am defining action path as showBeanValue and it is going to forward to page showBeanValue.jsp when some one access the showBeanValue.do in url.

In the second statement I am creating a dummy form since the the html form action should not be empty.

 
  <%@ taglib uri="http://struts.apache.org/tags-html" prefix="html"%>
  <%@ taglib uri="http://struts.apache.org/tags-bean" prefix="bean"%>     
  <html:form action="/Login">
    <bean:write name="userBean" property="userName"></bean:write>
    <bean:write name="userBean" property="userAge"></bean:write>
  </html:form>

Running Iterator Through Bean Stored in Map List

public class Iterator extends ActionSupport
{
   Map nmap = new HashMap<String, List<Person>>();
	
   public String execute()
   {
      Person objPerson    = new Person();

      objPerson.userName  = "Name1";
      objPerson.age 	    = 25;
      List<Person> myList = new ArrayList<Person>();
      myList.add(objPerson);
		
      nmap.put("Mugil", myList);
	
      objPerson.userName   = "Name2";
      objPerson.age 	     = 26;
      List<Person> myList2 = new ArrayList<Person>();
      myList2.add(objPerson);
		
      nmap.put("Mani", myList2);
		
      objPerson.userName    = "Name3";
      objPerson.age 	      = 27;
      List<Person> myList3  = new ArrayList<Person>();
      myList3.add(objPerson);
		
      nmap.put("Vinu", myList3);
		
      setNmap(nmap);
		
      return SUCCESS;
   }
	
   public Map getNmap() 
   {
     return nmap;
   }

   public void setNmap(Map nmap) 
   {
     this.nmap = nmap;
   }
}

Person Bean Code

class Person
{
    String userName;
    int age;

    public int getAge() {
      return age;
    }

    public void setAge(int age) {
      this.age = age;
    }

    public String getUserName() {
      return userName;
    }
	
    public void setUserName(String userName) {
      this.userName = userName;
    }
}

JSP Page Using Struts2 Tag

<table>
<s:iterator value="nmap">
     <s:iterator var="Person" value="value">
      <tr>
     	<td>
    	  <s:property value="key" />	
    	</td>
        <td>
      	  <s:property value="age" />
    	</td>
      </tr>
      </s:iterator>
</s:iterator>
</table>

Action Class Code

public class DropDown extends ActionSupport{
    private List arrUserDetails = new ArrayList<Users>();

    public DropDown()
    {
        Users objUsers = new Users();
        objUsers.setUserId("101");
        objUsers.setUserName("User1");

        arrUserDetails.add(objUsers);

        objUsers.setUserId("102");
        objUsers.setUserName("User2");

        arrUserDetails.add(objUsers);

        objUsers.setUserId("103");
        objUsers.setUserName("User3");

        arrUserDetails.add(objUsers);
    }

    public String execute(){
        return SUCCESS;
    }

    public List getArrUserDetails() {
        return arrUserDetails;
    }


    public void setArrUserDetails(List arrUserDetails) {
        this.arrUserDetails = arrUserDetails;
    }
}

Users Bean Class

 public class Users
{
    private String userId;
    private String userName;

    public String getUserId() {
        return userId;
    }
    public void setUserId(String userId) {
        this.userId = userId;
    }
    public String getUserName() {
        return userName;
    }
    public void setUserName(String userName) {
        this.userName = userName;
    }
}

JSP Page Struts2 Tag

 <s:select label="Departments" list="departmentList" listKey="deptId" listValue="deptName" name="department"/>