我想在jsp上显示检索到的数据但是有一个概率

时间:2013-12-19 06:39:34

标签: hibernate jsp struts2

此模型类中的模型类生成注释和getter& setter方法

package com.model.pkg;

import java.io.Serializable;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.Table;


@Entity
@Table(name="knt_user_master")    
public class UnlockUserModel implements Serializable 
{
    public UnlockUserModel(){}

    @Id
    @GeneratedValue
    private int pk_value;   

    @Column(name="user_id")
    private String user_id;

    @Column(name="address")
    private String address;

    @Column(name="reg_email")
    private String reg_email;


    @Column(name="idnumber")
    private String idnumber;

    @Column(name="reg_mobile")
    private String reg_mobile;


    @Column(name="dob")
    private String dob;


    public int getPk_value() {
        return pk_value;
    }


    public void setPk_value(int pk_value) {
        this.pk_value = pk_value;
    }


    public String getUser_id() {
        return user_id;
    }


    public void setUser_id(String user_id) {
        this.user_id = user_id;

        System.out.println("userId sssssssssssssssssssss   "+user_id);
    }


    public String getAddress() {
        return address;
    }


    public void setAddress(String address) {
        this.address = address;
        System.out.println("address sssssssssssssssssssss   "+address);
    }


    public String getReg_email() {
        return reg_email;

    }


    public void setReg_email(String reg_email) {
        this.reg_email = reg_email;
        System.out.println("reg_email sssssssssssssssssssss   "+reg_email);
    }


    public String getIdnumber() {
        return idnumber;
    }


    public void setIdnumber(String idnumber) {
        this.idnumber = idnumber;
    }


    public String getReg_mobile() {
        return reg_mobile;
    }


    public void setReg_mobile(String reg_mobile) {
        this.reg_mobile = reg_mobile;
    }


    public String getDob() {
        return dob;
    }


    public void setDob(String dob) {
        this.dob = dob;
    }


}

这是一个dao文件,它写了一个从数据库中检索数据的代码

package com.dao.pkg;

public class UserDetailsDao 
{
    static SessionFactory sessionFactory= HibernateUtil.getSessionFactory();

        static Session session=sessionFactory.openSession();

      UnlockUserModel  unlockModelObj=new UnlockUserModel();
      ArrayList <UnlockUserModel>recList= new ArrayList<UnlockUserModel>();

      private String userid;
      public String getUserid() {
        return userid;
    }
    public void setUserid(String userid) {
        this.userid = userid;
    }

    @SuppressWarnings("unchecked")
    public String  execute() 
    {

        try{             

            System.out.println("Control in execute method of UserDetailDao ");
            System.out.println("Query at fetching data from knt_user_master "+query);

            recList = (ArrayList<UnlockUserModel>) query.list();

            System.out.println("Rec List Size At RegistrationDao   " + recList.size());

            if(recList!=null && !recList.isEmpty())
            {
                System.out.println("Inside recList!=null Blockkkkkkkkkkkkkkkkkk");

                for(Iterator it=recList.iterator(); it.hasNext();)
                {
                    UnlockUserModel data = (UnlockUserModel)it.next();      


                    data.setUser_id(data.getUser_id());
                    data.setAddress(data.getAddress());
                    data.setDob(data.getDob());
                    data.setIdnumber(data.getIdnumber());
                    data.setReg_email(data.getReg_email());
                    data.setReg_mobile(data.getReg_mobile());

                    System.out.println("UserId from database    ===== "+data.getUser_id());
                    System.out.println("Address from database   ====="+data.getAddress());
                    System.out.println("Email from database     ====="+data.getReg_email());
                    System.out.println("Mobilenum from database ====="+data.getReg_mobile());
                    System.out.println("DOB from database       ====="+data.getDob());
                    System.out.println("Uid from database       ====="+data.getIdnumber());
                }
                recList.add(unlockModelObj);
            }
        return "success";           

        }catch (Exception e) 
        {
            e.printStackTrace();
            return "error";
        }
    }
}

jsp页面,我希望通过使用迭代器打印数据iam无法打印它没有错误消息,没有警告但数据没有打印我不知道如何打印数据

<s:form name="user_detail" action="unlockUser" method="post" theme="simple">
    <s:iterator value="recList">
        <s:textfield name="user_id" value="%{unlockModelObj.user_id}" readonly="true"/>
        <s:textfield name="address" value="%{unlockModelObj.address}" readonly="true"/>
        <s:textfield name="reg_email" value="%{unlockModelObj.reg_email}"/>
        <s:textfield name="idnumber" value="%{unlockModelObj.idnumber}" readonly="true"/>
        <s:textfield name="reg_mobile" value="%{unlockModelObj.reg_mobile}" readonly="true"/>
        <s:textfield name="dob" value="%{unlockModelObj.dob}" readonly="true"/>
        <s:submit value="Unblock" name="Unblock"></s:submit>
    </s:iterator>   
</s:form>

1 个答案:

答案 0 :(得分:0)

假设所有其他工作正常,当您迭代List<UnlockModelObj>时,当前迭代元素已经是UnlockModelObj,因此请勿将其写入value属性。

您还需要通过IteratorStatus在name属性中指定索引,以将其正确设置为目标操作:

<s:form name="user_detail" action="unlockUser" method="post" theme="simple">
    <s:iterator value="recList" stat="ctr" >
        <s:textfield name="recList[%{#ctr.index}].user_id"    value="%{user_id}" readonly="true"/>
        <s:textfield name="recList[%{#ctr.index}].address"    value="%{address}" readonly="true"/>
        <s:textfield name="recList[%{#ctr.index}].reg_email"  value="%{reg_email}"/>
        <s:textfield name="recList[%{#ctr.index}].idnumber"   value="%{idnumber}" readonly="true"/>
        <s:textfield name="recList[%{#ctr.index}].reg_mobile" value="%{reg_mobile}" readonly="true"/>
        <s:textfield name="recList[%{#ctr.index}].dob"        value="%{dob}" readonly="true"/>
        <s:submit value="Unblock" name="Unblock" />
    </s:iterator>   
</s:form>