Search code examples
javahtmljspservletsjavabeans

how to create Multiple EmployeeBean objects


jsp page:

<%@page language="java" contentType="text/html charset=UTF-8" pageEncoding="UTF-8"%>
    <!DOCTYPE html>
    <html>  
    <head>  
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">  
<title>Timesheet Page</title>  
    </head>  
    <body>  
        <header>
            <h2>WEEKLY TIME SHEET MANAGEMENT V 1.0</h2>
        </header>

        <form action="TimeSheet" method="post">
            <fieldset style="width: 90%">  
                <legend>Timesheet</legend>   
                <h2>Time Sheet application</h2>
    <table border=1>
    <tr><th>Employee ID</th><th>Date</th><th>Time In</th><th>Time Out</th><th>Lunch</th><th>After Lunch Time in</th><th>After Lunch Time out</th><th>Task Description</th><th>Total Hours</th><th>Overtime</th> </tr>


        <tr> <td><input type="text" name="empid" required="required" /></td>   
    <td><input type="date" id="date" name="date"/></td>
    <td><input type="time" class="start" name="logintime"/></td>
    <td><input type="time" class="end"name="logouttime" /></td>
    <td><input type="time" class="lunch" name="lunch" /></td>
    <td><input type="time" class="startafterlunch" name="afterlunchlogin"/></td>
    <td><input type="time" class="endafterlunch" name="afterlunchlogout"/></td>
    <td><input type="textarea" name="task" required="required" /></td>
    <td><input class="totalTime" readonly="readonly" /></td>
    <td><input class="overTime" readonly="readonly" /></td></tr>
        <tr> <td><input type="text" name="empid" required="required" /></td>   
    <td><input type="date" id="date" name="date"/></td>
    <td><input type="time" class="start" name="logintime"/></td>
    <td><input type="time" class="end"name="logouttime" /></td>
    <td><input type="time" class="lunch" name="lunch" /></td>
    <td><input type="time" class="startafterlunch" name="afterlunchlogin"/></td>
    <td><input type="time" class="endafterlunch" name="afterlunchlogout"/></td>
    <td><input type="textarea" name="task" required="required" /></td>
    <td><input class="totalTime" readonly="readonly" /></td>
    <td><input class="overTime" readonly="readonly" /></td></tr>
        <tr> <td><input type="text" name="empid" required="required" /></td>   
    <td><input type="date" id="date" name="date"/></td>
    <td><input type="time" class="start" name="logintime"/></td>
    <td><input type="time" class="end"name="logouttime" /></td>
    <td><input type="time" class="lunch" name="lunch" /></td>
    <td><input type="time" class="startafterlunch" name="afterlunchlogin"/></td>
    <td><input type="time" class="endafterlunch" name="afterlunchlogout"/></td>
    <td><input type="textarea" name="task" required="required" /></td>
    <td><input class="totalTime" readonly="readonly" /></td>
    <td><input class="overTime" readonly="readonly" /></td></tr>
        <tr> <td><input type="text" name="empid" required="required" /></td>   
    <td><input type="date" id="date" name="date"/></td>
    <td><input type="time" class="start" name="logintime"/></td>
    <td><input type="time" class="end"name="logouttime" /></td>
    <td><input type="time" class="lunch" name="lunch" /></td>
    <td><input type="time" class="startafterlunch" name="afterlunchlogin"/></td>
    <td><input type="time" class="endafterlunch" name="afterlunchlogout"/></td>
    <td><input type="textarea" name="task" required="required" /></td>
    <td><input class="totalTime" readonly="readonly" /></td>
    <td><input class="overTime" readonly="readonly" /></td></tr>
        <tr> <td><input type="text" name="empid" required="required" /></td>   
    <td><input type="date" id="date" name="date"/></td>
    <td><input type="time" class="start" name="logintime"/></td>
    <td><input type="time" class="end"name="logouttime" /></td>
    <td><input type="time" class="lunch" name="lunch" /></td>
    <td><input type="time" class="startafterlunch" name="afterlunchlogin"/></td>
    <td><input type="time" class="endafterlunch" name="afterlunchlogout"/></td>
    <td><input type="textarea" name="task" required="required" /></td>
    <td><input class="totalTime" readonly="readonly" /></td>
    <td><input class="overTime" readonly="readonly" /></td></tr>
    </table>
            </fieldset>      
             <input type="submit" value="Submit">
        </form>
       <a href="logout.jsp">Logout</a>
    </body>  
    </html>  

EmployeeBean: Its for only one row.

package com.eis.bean;

public class EmployeeBean {
    private String empid;
    private java.sql.Date logindate;
    private String logintime;
    private String logouttime;
    private String lunch;
    private String afterlunchlogin;
    private String afterlunchlogout;
    private String task;
    private String total;
    private String overtime;

    public String getEmpid() {
        return empid;
    }

    public void setEmpid(String empid) {
        this.empid = empid;
    }

    public java.sql.Date getLogindate() {
        return logindate;
    }

    public void setLogindate(java.sql.Date logindate) {
        this.logindate = logindate;
    }

    public String getLogintime() {
        return logintime;
    }

    public void setLogintime(String logintime) {
        this.logintime = logintime;
    }

    public String getLogouttime() {
        return logouttime;
    }

    public void setLogouttime(String logouttime) {
        this.logouttime = logouttime;
    }

    public String getLunch() {
        return lunch;
    }

    public void setLunch(String lunch) {
        this.lunch = lunch;
    }

    public String getAfterlunchlogin() {
        return afterlunchlogin;
    }

    public void setAfterlunchlogin(String afterlunchlogin) {
        this.afterlunchlogin = afterlunchlogin;
    }

    public String getAfterlunchlogout() {
        return afterlunchlogout;
    }

    public void setAfterlunchlogout(String afterlunchlogout) {
        this.afterlunchlogout = afterlunchlogout;
    }

    public String getTask() {
        return task;
    }

    public void setTask(String task) {
        this.task = task;
    }

    public String getTotal() {
        return total;
    }

    public void setTotal(String total) {
        this.total = total;
    }

    public String getOvertime() {
        return overtime;
    }

    public void setOvertime(String overtime) {
        this.overtime = overtime;
    }

    @Override
    public String toString() {
        return "EmployeeBean [empid=" + empid + ",logindate=" + logindate + ", logintime=" + logintime+ ", logouttime=" + logouttime + ", lunch=" + lunch+ ", afterlunchlogin=" + afterlunchlogin+ ", afterlunchlogout=" + afterlunchlogout+ ", task=" + task+ ", total=" + total+ ",overtime=" + overtime+ "]";
    }

}

this EmployeeBean is only for 1 row table, but i want to make that for five rows that to I wanted to know how to create multiple EmployeeBean Objects. please help... Thnaks!


Solution

  • can you try this,

    <%! int TOTAL_NUMBER_OF_ROW = 10; %>
    <form action="TimeSheet" method="post">
                <fieldset style="width: 90%">  
                    <legend>Timesheet</legend>   
                    <h2>Time Sheet application</h2>
        <table border=1>
        <tr><th>Employee ID</th><th>Date</th><th>Time In</th><th>Time Out</th><th>Lunch</th><th>After Lunch Time in</th><th>After Lunch Time out</th><th>Task Description</th><th>Total Hours</th><th>Overtime</th> </tr>
    
        <%for(int j =0;j<TOTAL_NUMBER_OF_ROW;j++){ %>
    
            <tr> 
        <td><input type="text" name="empid" required="required" /></td>   
        <td><input type="date" id="date" name="date"/></td>
        <td><input type="time" class="start" name="logintime"/></td>
        <td><input type="time" class="end"name="logouttime" /></td>
        <td><input type="time" class="lunch" name="lunch" /></td>
        <td><input type="time" class="startafterlunch" name="afterlunchlogin"/></td>
        <td><input type="time" class="endafterlunch" name="afterlunchlogout"/></td>
        <td><input type="textarea" name="task" required="required" /></td>
        <td><input class="totalTime" readonly="readonly" /></td>
        <td><input class="overTime" readonly="readonly" /></td>
        </tr>
    
        <%}%>
    
    
        </table>
                </fieldset>      
                 <input type="submit" value="Submit">
            </form>