10,607
社区成员
发帖
与我相关
我的任务
分享
import java.util.ArrayList;
import java.util.List;
public class UserForm {
String code;
private List<Country> countryList=new ArrayList<Country>();
public String getCode() {
return code;
}
public void setCode(String code) {
this.code = code;
}
public List<Country> getCountryList() {
return countryList;
}
public void setCountryList(List<Country> countryList) {
this.countryList = countryList;
}
}
Country:
public class Country {
String zip;
String simple;
public Country() {
super();
// TODO Auto-generated constructor stub
}
public Country(String zip, String simple) {
super();
this.zip = zip;
this.simple = simple;
}
public String getZip() {
return zip;
}
public void setZip(String zip) {
this.zip = zip;
}
public String getSimple() {
return simple;
}
public void setSimple(String simple) {
this.simple = simple;
}
}
action
import java.util.ArrayList;
import java.util.List;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
import org.apache.struts.actions.DispatchAction;
public class UserFormAction extends DispatchAction {
public ActionForward build(ActionMapping arg0, ActionForm arg1,
HttpServletRequest arg2, HttpServletResponse arg3) throws Exception {
UserForm uf=new UserForm();
uf.setCode("china");
List<Country> countryList=new ArrayList<Country>();
countryList.add(new Country("264000","yantai"));
uf.setCountryList(countryList);
arg2.setAttribute("uf", uf);
ActionForward forward=arg0.findForward("new");
return forward;
}
}
struts.xml
<action
path="/build"
parameter="type"
scope="request"
type="net.apobates.struts.UserFormAction">
<forward name="new" path="/form.jsp" />
</action>
<%@ page language="java" contentType="text/html; charset=utf-8"
pageEncoding="utf-8"%>
<%@taglib uri="/WEB-INF/struts-html.tld" prefix="html" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Insert title here</title>
</head>
<body>
<html:select name="uf" property="code" >
<html:optionsCollection name="uf" property="countryList" label="simple" value="zip" />
</html:select>
</body>
</html>
<html:select property="code">
<html:options collection="list" property="value" labelProperty="label"/></html:select>