Search This Blog

Wednesday, 15 August 2018

5. Write a multilayered JSP application to read and store employee Information in Database.


5. Write a multilayered JSP application to read and store employee information. Read employee name, employee identification number, Department, Designation, Basic Salary, TA, DA, HRA, PF, LIC (in percentage) as input through a proper user interface page. Also calculate TA Amount, DA Amount, HRA Amount, PF Amount, LIC Amount, Total Allowances, Total Deductions, Gross Salary and Net Salary components of the employee. Along with the employee information store the salary details in the MS Access table.
Code for Emp13.html:
<!-- 13. HTML Program to accept Employee Details. -->
<html>
 <head>

 <title>Employee Details</title>
 </head>
 <body>
 <h3>Enter Employee Details:</h3>
 <form action="Emp13.jsp" method="POST" >
 <table >
 <tr><td>Employee Name:</td><td><input type="text" name="ename" ></td></tr>
 <tr><td>Employee ID:</td><td><input type="text" name="empid"></td></tr>
 <tr><td>Department:</td><td><input type="text" name="dept"></td></tr>
 <tr><td>Designation:</td><td><input type="text" name="des"></td></tr>
 <tr><td>Basic Salary:</td><td><input type="text" name="bsal"></td></tr>
 <tr><td>TA(%):</td><td><input type="text" name="ta"></td></tr>
 <tr><td>DA(%):</td><td><input type="text" name="da"></td></tr>
 <tr><td>HRA(%):</td><td><input type="text" name="hra"></td></tr>
 <tr><td>PF(%):</td><td><input type="text" name="pf"></td></tr>
 <tr><td>LIC(%):</td><td><input type="text" name="lic"></td></tr>

 <tr><td><input type="submit" value="Evaluate & Store"></td>
 <td><input type="reset" value="Reset"></td></tr>
 </table>
 </form>
 </body>
</html>

Code for Emp13.jsp:
<!-- 13. JSP Program to Evaluate Salary Details of an Employee and Store in Database.-->
<html>
<head>
<%@ page import="java.sql.*" %>
</head>
<body bgcolor="beige">

<%
  
    String ename=request.getParameter("ename");
    String empid=request.getParameter("empid");
    String dept=request.getParameter("dept");
    String des=request.getParameter("des");
    double bsal=Double.valueOf(request.getParameter("bsal"));
    double ta=Double.valueOf(request.getParameter("ta"));
    double ta2=bsal*ta/100;
    double da=Double.valueOf(request.getParameter("da"));
    double da2=bsal*da/100;
    double hra=Double.valueOf(request.getParameter("hra"));
    double hra2=bsal*hra/100;
    double pf=Double.valueOf(request.getParameter("pf"));
    double pf2=bsal*pf/100;
    double lic=Double.valueOf(request.getParameter("lic"));
    double lic2=bsal*lic/100;
    double allowance;
    double deduction;
    double gsal;
    double netsal;

    allowance = (bsal*ta)/100 + (bsal*da)/100 + (bsal*hra)/100;
    deduction = (bsal*pf)/100 + (bsal*lic)/100;
    gsal = bsal + allowance;
    netsal = gsal - deduction;
  
    try
    {
        out.println("<h2>Information Stored Successfully!</h2>");
        Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
        Connection con=DriverManager.getConnection("jdbc:odbc:emp13");
        Statement st=con.createStatement();
        String s="insert into emp13 values('"+ename+"','"+empid+"','"+dept+"','"+des+"',"
            +bsal+","+allowance+","+gsal+","+deduction+","+netsal+");";
        st.executeQuery(s);
    }
    catch(Exception e)
    {
        //out.println(e);
    }
%>
</body>
</html>

No comments :

Post a Comment

FREE Hit Counters