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

struts2 单选框有关问题

2012-04-24 
struts2 单选框问题假设我有一个单选框在前台,HTML codes:formnametargetForm actionlogins:text

struts2 单选框问题
假设我有一个单选框在前台,

HTML code
            <s:form  name="targetForm" action="login">            <s:textfield name="username" label="用户名"></s:textfield>             <s:password name="password" label="密 码"></s:password>              <s:radio label="用户类型" name ="type" list= "{'学生','管理员'}"/>            <s:submit value="登陆" />                    </s:form>

  那么的话,我这个单选框
 
HTML code
<s:radio label="用户类型" name ="type" list= "{'学生','管理员','游客'}"/>

  里面的值有三个,我在后台的action里面获取不到单选框的值吗?
  例如我这么做:
Java code
public class LoginAction extends BaseAction{        private String type;    ……………………       //省略无关变量的setter    public String getType()    {        return type;    }    public void setType(String type)    {        this.type = type;    }

  然后就会报错:
严重: Servlet.service() for servlet jsp threw exception
tag 'radio', field 'list', name 'type': The requested list key '{'学生','管理员''}' could not be resolved as a collection/array/map/enumeration/iterator type[color=#FF0000][/color]. Example: people or people.{name} - [unknown location]

  1,难道不是用String类存放单选框的值吗?
  2,如何设置让单选框的默认选中 管理员那个选项呢?

[解决办法]
探讨

<s:radio label="用户类型" name ="type" list= "#{'student':‘学生','admin':'管理员','tourist':'游客'}"/>
这样写 加上key

热点排行