1

我是新来的struts。我想在 jsp 上向用户显示数据库中表的所有详细信息。请帮我做这些。

在此先感谢,维迪亚

LoginFormBean.java

public class LoginFormBean extends ValidatorForm 
{

    public String name;
    public String city;
    public String state;
    public String phone;
    public String mailId;
    public String gender;
    public String branch;
    private List studentDetails;

    public void setName(String name) {
        this.name = name;
    }

    public String getName() {
        return name;
    }

    public void setCity(String city) {
        this.city = city;
    }

    public String getCity() {
        return city;
    }

    public void setPhone(String phone) {
        this.phone = phone;
    }

    public String getPhone() {
        return phone;
    }

    public void setMailId(String mailId) {
        this.mailId = mailId;
    }

    public String getMailId() {
        return mailId;
    }

    public void setGender(String gender) {
        this.gender = gender;
    }

    public String getBranch() {
        return branch;
    }

    public void setBranch(String branch) {
        this.branch = branch;
    }

    public String getGender() {
        return gender;
    }
    public void setState(String state) {
        this.state = state;
    }
    public String getState() {
        return state;
    }

    public List getStudentDetails() {
        return studentDetails;
    }
    public void setStudentDetails(List studentDetails) {
        this.studentDetails = studentDetails;
    }


}

登录道.java

public class Logindao {
public List viewStudents()
    {

          Connection conn=DBUtil.getDBConnection();
          List list=new ArrayList();
          Statement stmt = null;
          ResultSet rs=null;
          String query="select * from student_info";

               stmt=conn.createStatement();
               rs= stmt.executeQuery(query);
              while(rs.next())
              {

                    list = new ArrayList();  
                    list.add(rs.getString("name"));
                    list.add(rs.getString("phone"));
                    list.add(rs.getString("email"));
                    list.add(rs.getString("city"));
                    list.add(rs.getString("state"));
                    list.add(rs.getString("gender"));
                    list.add(rs.getString("branch"));
              }

          }
              return list;
    }

RetrieveDataActionClass.java

public class RetrieveDataActionClass extends Action{

    public ActionForward execute(ActionMapping mapping,ActionForm form,HttpServletRequest request,HttpServletResponse response)throws Exception,ServletException
     {
            List list=new ArrayList();
            String key="success";
            Logindao dao=new Logindao();
            LoginFormBean formbean=(LoginFormBean)form;

    try{

        list=dao.viewStudents();
        formbean.setStudentDetails(dao.viewStudents());
        }
        catch(Exception e)
        {
           e.printStackTrace();
           System.out.println("Error occured");

        }
        return mapping.findForward(key);
        }
        } 

viewstudents.jsp

<body>
   <html:form action="/retrieve" method="post">
    <table border="1">  
    <tr>
    <th>Name</th>
    <th>Phone</th>
    <th>MailId</th>
    <th>City</th>
    <th>State</th>
    <th>Gender</th>
    <th>Branch</th>
    </tr>  

    <logic:iterate id="students" name="LoginFormBean" property="studentDetails">
    <tr>  
    <td><bean:write name="students" property="name"/></td>  
    <td><bean:write name="students" property="phone"/></td>  
    <td><bean:write name="students" property="mailId"/></td>  
    <td><bean:write name="students" property="city"/></td>  
    <td><bean:write name="students" property="state"/></td>  
    <td><bean:write name="students" property="gender"/></td>  
    <td><bean:write name="students" property="branch"/></td>  
    </tr>  
    </logic:iterate> 
    </table>
    </html:form>
  </body>

我的 sqlserver 数据库中有一个表' student_info '。列:姓名、电话、电子邮件、城市、州、性别、分支机构

我想在jsp中以以下格式显示输出。

姓名 电话 电子邮件 城市 州 性别 科

abc 55555 a@gmail.com hyd AP 女性 IT

xyz 55555 x@gmail.com bang KT 女 CSE

错误:

javax.servlet.ServletException:javax.servlet.jsp.JspException:在任何范围内找不到 bean:“LoginFormBean”

在此先感谢,维迪亚。

4

1 回答 1

2

您需要在您的 JSP 中实例化您的 bean“LoginFormBean”,然后再进行 logic:iterate 。你可以使用 use jsp:usebean 标记

于 2012-08-01T09:45:00.830 回答