struts2中如何把数据库中的值加入到下拉列表框中,获取数据库的方法已写,下面不知道咋弄,struts是新手
publicHashMapaddressMap(){HashMaphm=newHashMap();try{state=conn.createStatement();rs=...
public HashMap addressMap()
{
HashMap hm=new HashMap();
try
{
state=conn.createStatement();
rs=state.executeQuery("select * from address");
//System.out.print(rs.next());
while(rs.next())
{
hm.put(String.valueOf(rs.getInt("id")), rs.getString("address"));
System.out.println(hm.put(String.valueOf(rs.getInt("id")), rs.getString("address")));
System.out.println(String.valueOf(rs.getInt("id"))+rs.getString("address"));
//System.out.println(rs.getString("address"));
}
}
catch(SQLException e)
{
e.printStackTrace();
}
finally
{
try
{
rs.close();
state.close();
}
catch(SQLException e)
{
e.printStackTrace();
}
}
return hm;
} 展开
{
HashMap hm=new HashMap();
try
{
state=conn.createStatement();
rs=state.executeQuery("select * from address");
//System.out.print(rs.next());
while(rs.next())
{
hm.put(String.valueOf(rs.getInt("id")), rs.getString("address"));
System.out.println(hm.put(String.valueOf(rs.getInt("id")), rs.getString("address")));
System.out.println(String.valueOf(rs.getInt("id"))+rs.getString("address"));
//System.out.println(rs.getString("address"));
}
}
catch(SQLException e)
{
e.printStackTrace();
}
finally
{
try
{
rs.close();
state.close();
}
catch(SQLException e)
{
e.printStackTrace();
}
}
return hm;
} 展开
展开全部
private String name;
生成set、get方法
public HashMap addressMap()
{
list = new ArrayList<String>();
while(rs.next())
{
.................
HttpServletRequest request = ServletActionContext.getRequest();
request.setAttribute("map",hm);
request.setAttribute("aa",name);
}
}
JSP页面下拉菜单:
<s:select list="#request.map" cssStyle="width:83px;" name="name"
listKey="key"
listValue="value" headerKey="" headerValue="--请选择--" value="#request.aa" id="select">
</s:select>
生成set、get方法
public HashMap addressMap()
{
list = new ArrayList<String>();
while(rs.next())
{
.................
HttpServletRequest request = ServletActionContext.getRequest();
request.setAttribute("map",hm);
request.setAttribute("aa",name);
}
}
JSP页面下拉菜单:
<s:select list="#request.map" cssStyle="width:83px;" name="name"
listKey="key"
listValue="value" headerKey="" headerValue="--请选择--" value="#request.aa" id="select">
</s:select>
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询