请问怎么设置struts的html:radio默认为选中状态。 谢谢! 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 <label><html:radio property="xxx">选中</label></html:radio><label><html:radio property="yyy">未选中</html:radio></label>LZ试试吧!呵呵 你需要在Action中先给这个RADIO控件赋值,很简单,直接用SET就行了 在</html>的最后加上(就是说当页面执行完时)<script> document.all("sex")[0].checked=true;//第一个radio选中</script> 试试这个<html:radio property="xxx" CHECKED>选项</label></html:radio> 你需要在Action中先给这个RADIO控件赋值,很简单,直接用SET就行了-----------------------这个赋值好像在而面载入的时候不起作用。 javapassion(村长赵大宝) ( ) 信誉:100 -----------------------没看明白你的啥意思呀!hackangcn(龙卷风) ( ) 信誉:100 ---------------------------------你的只是简单选中,我是要在后台取出数据,根据数据来选中的。suncheng_hong(亮) ( ) 信誉:100 -----------------------------------------没有CHECKED这个属性的。 从数据库中取出数据后,在action中,把该值(就是html:radio的name对应的)set进Formbean去。你那些普通的html:text是怎么set到bean里面的,这个也类是。 在action中????请问应该怎么set .谢谢!!!我在bean里set了不行?不知道怎么在action里set. ..上班时间不能聊q。你在普通的html:text是在bean里set,那么这个也一样,在哪里set无所谓,只要最后页面的FromBean里面有值就可以了。你说的不行,使页面报错,还是不出来? 我看不到你具体的代码,不知道你错在哪里。反正这个思路是可以用的。要不我发我的例子给你看看:Action中:TUserinfo userInfo = userInfoDAO.findUserInfo(_user,_lid); //通过数据库,以bean返回值 if(userInfo!=null) { UserInfoForm userInfoForm = (UserInfoForm) form; userInfoForm.setUserInfo(userInfo); //把值赋于bean }Form中: private String sexId; private TUserinfo userInfo;.... public String getSexId() { return sexId; } public void setSexId(String sexId) { this.sexId = sexId; } public void setUserInfo(TUserinfo userInfo) { this.userInfo = userInfo; this.linkMan = userInfo.getLinkman(); this.sexId = userInfo.getSex().getSexid()+""; this.linkmanDepartment = userInfo.getLinkmandepartment(); this.linkmanPosition = userInfo.getLinkmanposition(); this.telCountry = userInfo.getTelcountry(); this.telCity = userInfo.getTelcity(); this.telBase = userInfo.getTelbase(); this.faxCountry = userInfo.getFaxcountry(); this.faxCity = userInfo.getFaxcity(); this.faxBase = userInfo.getFaxbase(); this.mobie = userInfo.getMobie(); this.address = userInfo.getAddress(); this.post = userInfo.getPost(); this.email = userInfo.getEmail(); this.url = userInfo.getUrl(); }Jsp中: <tr bgcolor="#FFFFFF"> <td align="right" bgcolor="#EEFFEF"><div align="right"><span class="orange">*</span>性别:</div></td> <td><html:radio property="sexId" value="1" > 先生</html:radio> <html:radio property="sexId" value="2"> 女士</html:radio></td> </tr> 谢谢楼上的,我再试试.刚才不报错,什么也不显示.应该是null值. <html:radio property="radioStation" value="left">左边显示 </html:radio> <html:radio property="radioStation" value="right">右边显示 </html:radio> <jsp:getProperty name="siteStyle" property="radioStation"/>----------------------------------------------------jsp代码如上:<jsp:getProperty打印出来的值是left,但"左边显示"这个单选扭并不有选中.----------------------------------------------------下面是生成的html代码.<input type="radio" name="radioStation" value="left">左边显示 <input type="radio" name="radioStation" value="right">右边显示 left <jsp:useBean id="siteStyle" scope="request" class="com.lideyong.server.bean.SiteStyle"></jsp:useBean><%siteStyle.setSession(request.getSession());siteStyle.getThis();%>----------------------------以上是jsp里.------------------------ 你的jsp里面的,用没有用<html:form method="post" action="/userInfoAdd.do" >?还是用<html>? 既然用了struts标签?为什么还混用jsp的?而struts中radio的内容必须 set/get方法 哦!我刚才试了一下就行了.原因get/set必须写在Struts的Form里才行,写在bean里并不能给struts的标签赋值呀! 晕,想从数据库获取数据再选中,直接在action里面set一下formbean中对应的属性就ok了真不知道为什么这个问题要讨论这么长 LZ刚刚学Struts吧~呵呵!慢慢来 不要急 在</html>的最后加上(就是说当页面执行完时)<script> document.all("sex")[0].checked=true;//第一个radio选中</script>龙卷风朋友说的才是正解!! 用HttpClient模拟访问网站报错 显示数据库读取信息一直存在异常,纠结很久了~~~ 如何在JSP里网站首页自动选择语言转跳? 请不吝赐教 请问 JSP 有没有 像 asp.net 的 Session 和 Application 变量 xfire客户端空指针,高手帮帮忙呀 Java小游戏 SSH整合时 只有在增加是报错,是没找到hibernate动态代理的类 一个分页的打印问题??? 如何尽快学会JSP? 请教一个小问题关于struts标签的 动态表格数据如何存入数据库?
<label><html:radio property="yyy">未选中</html:radio></label>LZ试试吧!呵呵
document.all("sex")[0].checked=true;//第一个radio选中
</script>
<html:radio property="xxx" CHECKED>选项</label></html:radio>
这个赋值好像在而面载入的时候不起作用。
没看明白你的啥意思呀!hackangcn(龙卷风) ( ) 信誉:100
---------------------------------
你的只是简单选中,我是要在后台取出数据,根据数据来选中的。
suncheng_hong(亮) ( ) 信誉:100
-----------------------------------------
没有CHECKED这个属性的。
反正这个思路是可以用的。要不我发我的例子给你看看:Action中:
TUserinfo userInfo = userInfoDAO.findUserInfo(_user,_lid); //通过数据库,以bean返回值
if(userInfo!=null)
{
UserInfoForm userInfoForm = (UserInfoForm) form;
userInfoForm.setUserInfo(userInfo); //把值赋于bean
}Form中:
private String sexId;
private TUserinfo userInfo;
....
public String getSexId() {
return sexId;
} public void setSexId(String sexId) {
this.sexId = sexId;
} public void setUserInfo(TUserinfo userInfo) {
this.userInfo = userInfo;
this.linkMan = userInfo.getLinkman();
this.sexId = userInfo.getSex().getSexid()+"";
this.linkmanDepartment = userInfo.getLinkmandepartment();
this.linkmanPosition = userInfo.getLinkmanposition();
this.telCountry = userInfo.getTelcountry();
this.telCity = userInfo.getTelcity();
this.telBase = userInfo.getTelbase();
this.faxCountry = userInfo.getFaxcountry();
this.faxCity = userInfo.getFaxcity();
this.faxBase = userInfo.getFaxbase();
this.mobie = userInfo.getMobie();
this.address = userInfo.getAddress();
this.post = userInfo.getPost();
this.email = userInfo.getEmail();
this.url = userInfo.getUrl();
}Jsp中:
<tr bgcolor="#FFFFFF">
<td align="right" bgcolor="#EEFFEF"><div align="right"><span class="orange">*</span>性别:</div></td>
<td><html:radio property="sexId" value="1" >
先生</html:radio>
<html:radio property="sexId" value="2">
女士</html:radio></td>
</tr>
</html:radio>
<html:radio property="radioStation" value="right">右边显示
</html:radio>
<jsp:getProperty name="siteStyle" property="radioStation"/>
----------------------------------------------------
jsp代码如上:<jsp:getProperty打印出来的值是left,但"左边显示"这个单选扭并不有选中.----------------------------------------------------
下面是生成的html代码.
<input type="radio" name="radioStation" value="left">左边显示
<input type="radio" name="radioStation" value="right">右边显示
left
</jsp:useBean>
<%
siteStyle.setSession(request.getSession());
siteStyle.getThis();
%>----------------------------以上是jsp里.------------------------
还是用<html>?
而struts中radio的内容必须 set/get方法
原因get/set必须写在Struts的Form里才行,写在bean里并不能给struts的标签赋值呀!
真不知道为什么这个问题要讨论这么长
document.all("sex")[0].checked=true;//第一个radio选中
</script>龙卷风朋友说的才是正解!!