如何把信息显示在下拉列表,并同时能获取 我的实体类有个字段是城市,我是用struts1.2, 也获取了数据库中城市的列表信息,页面上的下拉菜单怎么写才能显示我获取的数据? 还有我如何实现选择后也能获取选择的城市,请问怎么写?文本框我就知道怎么写,就是在name属性那里写实体类加相应的属性名就可以绑定了,主要是页面的那个下拉列表不熟悉。。 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 <select id="city" onchange="check();"> <% if(null!=list && list.size()>0){ for(Iterator it = list.iterator();it.hasNext();){ AddressEntity ae = (AddressEnttiy)it.next(); out.println("<option value='"+ ae.getCity() +"'>"+ ae.getCity() +"</option>"); } } %></select><script> function check(){ var city = document.getElementById("city"); for(i=0;i<city.length;i++){ if(city[i].selected){ alert("选中值为:"+city[i].value); } } } </script> 上面的list是通过request获得的:<% List list = (ArrayList)request.getAttribute("list");%> 楼上兄弟,人家都struts了,你还给java代码,啥时才能从页面彻底拼弃java代码啊。直接使用标签啊,楼主兄弟。不知道怎么使,查! 用了标签在页面生成的还不是html代码,用js不就能直接获取了、、、 <html:select property="city.cityId"> <html:option value="0">请选择</html:option> <html:optionsCollection name="cityList" label="cityName" value="cityId" /></html:select> 查询到城市列表 cityList 存入request 中即可 不能执行 数据库 批处理 更新 orcale的登录问题 用Tomcat5.0.28调试jsp的一个问题 跨页面的事务问题 EJB Session not exist at vcvcx WebSphere6.0试用版不支持EntityBean开发吗? 关于Spring和Struts一些入门前的问题...!? 学struts的留个QQ吧 请教Runtime.getRuntime().exec调用cmd时命令中有特殊字符的问题 struts2 自定义验证拦截器的疑惑和标签<s:property> 如何将HashMap按照value值进行排序
<select id="city" onchange="check();">
<%
if(null!=list && list.size()>0){
for(Iterator it = list.iterator();it.hasNext();){
AddressEntity ae = (AddressEnttiy)it.next();
out.println("<option value='"+ ae.getCity() +"'>"+ ae.getCity() +"</option>");
}
}
%>
</select>
<script>
function check(){
var city = document.getElementById("city");
for(i=0;i<city.length;i++){
if(city[i].selected){
alert("选中值为:"+city[i].value);
}
}
}
</script>
<%
List list = (ArrayList)request.getAttribute("list");
%>
不知道怎么使,查!
<html:select property="city.cityId">
<html:option value="0">请选择</html:option>
<html:optionsCollection name="cityList" label="cityName"
value="cityId" />
</html:select>