日期:2014-05-19  浏览次数:20691 次

关于struts2从页面取值的问题
我的页面如下:
HTML code

<html>
  <body>
  <center>
  <h1>注册新用户</h1>
  <p>带*的,你懂的!</p>
      <s:form action="registValidate" method="post" name="regist">
      <!-- 加入了Token标记 -->
        <s:token/>
          <s:textfield name="username" label="姓名" required="true"/>
          <s:password name="password" label="密码" required="true"/>
          <s:password name="confirmPassword" label="确认密码" required="true"/>
          <s:textfield name="userAge" label="年龄" required="true"/>
          <s:radio name="userSex" list="#{'男':'男','女':'女'}" label="性别" required="true"/>
          <s:textfield name="tel" label="电话" required="true" required="true"/>
          <s:doubleselect label="所在城市" labelposition="top" name="address" list="{'江西','浙江'}"
          doubleName="city" doubleList="top=='江西'?{'南昌','赣州','九江','新余','南康','上饶'}:
          {'宁波','杭州','建德','富阳','临安','余姚'}" doubleSize="3" required="true"/>
          <s:submit value="提交"/>
          <s:reset value="重置"/>
      </s:form>
      </center>
  </body>
</html>


ACTION代码如下
Java code

package bank.action;

import bank.domain.UserInfo;
import bank.service.UserFacade;
import bank.service.UserFacadeImpl;

import com.opensymphony.xwork2.ActionSupport;

public class RegistAction extends ActionSupport{
    //private String userNo;//用户账号,系统自动生成
    private String username;//用户名
    private String password;//密码
    private String confirmPassword;//确认密码
    private int userAge;//用户年龄
    private String userSex;//性别
    private String tel;//用户电话号码
    private String address;//用户住址
    private String city;
    //private UserInfo userInfo=new UserInfo();
    
    public String getUsername() {
        return username;
    }

    public void setUsername(String username) {
        this.username = username;
    }

    public String getPassword() {
        return password;
    }

    public void setPassword(String password) {
        this.password = password;
    }

    public String getConfirmPassword() {
        return confirmPassword;
    }

    public void setConfirmPassword(String confirmPassword) {
        this.confirmPassword = confirmPassword;
    }

    public int getUserAge() {
        return userAge;
    }

    public void setUserAge(int userAge) {
        this.userAge = userAge;
    }

    public String getUserSex() {
        return userSex;
    }

    public void setUserSex(String userSex) {
        this.userSex = userSex;
    }
    
    public String getTel() {
        return tel;
    }

    public void setTel(String tel) {
        this.tel = tel;
    }

    public String getAddress() {
        return address;
    }

    public void setAddress(String address) {
        this.address = address;
    }
    public String getCity() {
        return city;
    }

    public void setCity(String city) {
        this.city = city;
    }
    public String regist(){
    //注册新用户操作
        UserFacade userFacade=new UserFacadeImpl();
        UserInfo userInfo=new UserInfo();
        //从页面取得对应的值,并且赋给对象userInfo
        String address=getAddress()+getCity();//从doubleselect标签中获得注册用户的地址,包括父子列表中的
        userInfo.setAddress(address);
        //this.userInfo.setConfirmPassword(getConfirmPassword());
        userInfo.setPassword(getPassword());[color=#FF0000]//调试时,可