首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 网站开发 > CSS >

struts中<html:radio>标签默许选中的解决方案

2012-10-29 
struts中html:radio标签默认选中的解决方案网上说了很多,用JS解决的我就不说,不是我喜欢的道道??要让ht

struts中<html:radio>标签默认选中的解决方案

网上说了很多,用JS解决的我就不说,不是我喜欢的道道

?

?要让<html:radio>选择很关键的一点,就是,这个JSP势必对应的一个actionform吧,给它个初始值就OK了

?

但是这个方案不好,默认值我怎么知道,如果这个值要动态呢?

?

请注意到name属性

?

性别<html:radio  value="1" property="sex" name="user">男</html:radio>            <html:radio value="2" property="sex"  name="user">女</html:radio>            <html:radio value="0" property="sex"  name="user">保密</html:radio>

?

只要在request,session等范围内存在user,这个上面的标签就会根据user.sex的值产生默认选中了

?

?

?

1 楼 lionel8888 2010-06-04   最开始就默认选择一项怎么办? 2 楼 wyf9267 2011-10-27   lionel8888 写道最开始就默认选择一项怎么办?
只能在jsp对应action中为user赋值
request.setAttribute("user","2");
return mapping.findFoward(对应的jsp页面);
就可以默认选中 “女”了

热点排行