当前位置: 代码迷 >> Web前端 >> struts2 传接数组、List、Map
  详细解决方案

struts2 传接数组、List、Map

热度:136   发布时间:2012-09-14 23:00:49.0
struts2 传递数组、List、Map

jsp文件

?

数组:
??? ?<s:textfield name="ages" value="a1"></s:textfield>
??? ?<s:textfield name="ages" value="a2"></s:textfield>
??? ?<s:textfield name="ages" value="a3"></s:textfield>
??? ?
??? ?<s:textfield name="names[0]" value="n1"></s:textfield>
??? ?<s:textfield name="names[1]" value="n2"></s:textfield>
??? ?<s:textfield name="names[2]" value="n3"></s:textfield>
??List:
??? ?<s:textfield name="lastName[0]" value="11"></s:textfield>
??? ?<s:textfield name="lastName[1]" value="21"></s:textfield>
??? ?<s:textfield name="lastName[2]" value="31"></s:textfield>
?????
??Map
??? ?<s:textfield name="maid.mary"></s:textfield>
??? ?<s:textfield name="maid['beth']"></s:textfield>

?

java文件

?

System.out.println(ages.toString()+names.toString()+getLastName().toString());
?????
??Map map = getMaid();

System.out.println(map.get("mary")+":"+map.get("beth"));

/*数组*/
?private String[] ages;
?

?/**
? * @return the ages
? */
?public String[] getAges() {
??return ages;
?}

?/**
? * @param ages the ages to set
? */
?public void setAges(String[] ages) {
??this.ages = ages;
?}
?
?private String[] names = new String[10];

?/**
? * @return the names
? */
?public String[] getNames() {
??return names;
?}

?/**
? * @param names the names to set
? */
?public void setNames(String[] names) {
??this.names = names;
?}
?
?private List<Integer> lastName;

?/**
? * @return the lastName
? */
?public List<Integer> getLastName() {
??return lastName;
?}

?/**
? * @param lastName the lastName to set
? */
?public void setLastName(List<Integer> lastName) {
??this.lastName = lastName;
?}
?
?private Map maid;

?/**
? * @return the maid
? */
?public Map getMaid() {
??return maid;
?}

?/**
? * @param maid the maid to set
? */
?public void setMaid(Map maid) {
??this.maid = maid;
?}

  相关解决方案