【问题标题】:how to create Multiple EmployeeBean objects如何创建多个 EmployeeBean 对象
【发布时间】:2015-10-30 08:21:15
【问题描述】:

jsp页面:

<%@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: 它只有一行。

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+ "]";
    }

}

此 EmployeeBean 仅适用于 1 行表,但我想为我想知道如何创建多个 EmployeeBean 对象的五行制作它。请帮忙... 谢谢!

【问题讨论】:

  • 嘿,请问你的文件是html还是JSP?还想问你,如果文件是jsp那么你舒服吗?
  • @Mr.VishalJGajera 是的,它在 jsp 中
  • @dear downvoter 你能告诉我你投了反对票吗?至少在这里提到它而不是投票
  • 请原谅我,我从不投反对票。
  • 抱歉不适合你

标签: java html jsp servlets javabeans


【解决方案1】:

你可以试试这个,

<%! 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>

【讨论】:

  • 如果我使用了这个,它会帮助我用这个 EmployeeBean 插入多行数据吗??
  • @dpk,不要害怕使用它,但要注意我没有注意值的一件事,所以当你要实现它时,请根据你的 bean 的值填充值。否则一切都很好。
  • 谢谢!!你能看看这个并帮帮我吗!这对我有很大帮助...再次感谢! stackoverflow.com/questions/33411108/…
  • 我已经为您编辑了 1 行插入成功,请检查并帮助我!谢谢stackoverflow.com/questions/33411108/…
  • 如果我想根据行给出不同的名称,例如输入日期为 date1 date2 date3 等等......你有什么解决方案
猜你喜欢
  • 1970-01-01
  • 2017-02-03
  • 1970-01-01
  • 2012-09-16
  • 2014-10-08
  • 2011-11-21
  • 2017-09-21
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多