使用struts 2中的select标签映射操作

时间:2011-06-13 10:06:58

标签: struts2

  <s:select name="country" list="countryList" listKey="countryId" 
     listValue="countryName" headerKey="0" headerValue="Country"
     label="Select a country" />

country.java

    package vaannila;

    public class Country {

      private int countryId;

      private String countryName;

      Country(int countryId, String countryName) {
        this.countryId = countryId;
        this.countryName = countryName;
      }

      public int getCountryId() {
        return countryId;
      }

      public void setCountryId(int countryId) {
        this.countryId = countryId;
      }

      public String getCountryName() {
        return countryName;
      }

      public void setCountryName(String countryName) {
        this.countryName = countryName;
      }
}

HelloWorld.java

public class HelloWorld {

private String message;

private String userName;
private String gender;
private boolean language;
private ArrayList<Country> countryList;

public HelloWorld(){
countryList = new ArrayList<Country>();
    countryList.add(new Country(1, "India"));
    countryList.add(new Country(2, "USA"));
    countryList.add(new Country(3, "France"));

}   

public boolean isLanguage() {
    return language;
}

public void setLanguage(boolean language) {
    this.language = language;
}

public String getGender() {
    return gender;
}

public void setGender(String gender) {
    this.gender = gender;
}

public ArrayList<Country> getCountryList() {
    return countryList;
}

public void setCountryList(ArrayList<Country> countryList) {
    this.countryList = countryList;
}

public String execute()  {
    setMessage("Hello " + getUserName());
    return "SUCCESS";
}

public String getMessage() {
    return message;
}

public void setMessage(String message) {
    this.message = message;
}

public String getUserName() {
    return userName;
}

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

struts.xml中

<struts>
  <!-- Configuration for the default package. -->
  <package name="default"  extends="struts-default">
     <action name="HelloWorld" class="vaannila.HelloWorld">
        <result name="SUCCESS">/success.jsp</result>
     </action>
  </package>
</struts>

Http状态500

org.apache.jasper.JasperException:标记'select',字段'list',名称'country':请求的列表键'countryList'无法解析为集合/数组

这是错误提交。 任何人都可以帮助我

1 个答案:

答案 0 :(得分:0)

您的country动作类中缺少HelloWorld个实例变量和相应的getter / setter ......