0% found this document useful (0 votes)
40 views

Ex3 - Payroll System in EJB

This document describes the development of a payroll system using Java EE and EJBs. It includes the index.jsp page for entering employee data, the PayrollServlet class for processing the data and invoking EJB methods to calculate payroll values, and code to insert data into and retrieve data from a database.

Uploaded by

suganya004
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
40 views

Ex3 - Payroll System in EJB

This document describes the development of a payroll system using Java EE and EJBs. It includes the index.jsp page for entering employee data, the PayrollServlet class for processing the data and invoking EJB methods to calculate payroll values, and code to insert data into and retrieve data from a database.

Uploaded by

suganya004
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
You are on page 1/ 9

Ex 3: Develop the Payroll system in EJB

Algorithm

Index.jsp

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>JSP Page</title>
</head>
<body>

<h1>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&n
bsp;&nbsp;&nbsp;&nbsp;&nbsp;

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
&nbsp;&nbsp;&nbsp;PAYROLL SYSTEM</h1>
<form id="form" method="post"
action="http://localhost:8080/Payroll/PayrollServlet">
<p>

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
<table style="width: 51%; height: 323px; z-index: 1; left: 316px; top: 167px;
position: absolute;"
border="1" bordercolor="#C00000">
<tr>
<td> <table class="style1">
<tr>
<td class="style2">
Name</td>
<td class="style3">
<input id="Text1" name="Name" type="text" /></td>
</tr>
<tr>
<td class="style2">
Designation</td>
<td class="style3">
<select id="Select1" name="D1">
<option id="Select">-Select-</option>
<option id="Director">Director</option>
<option id="Principal">Principal</option>
<option id="Professor">Professor</option>
<option id="Associate Professor">Associate Professor</option>
<option id="Assistant Professor">Assistant Professor</option>
<option id="Senior Lecturer">Senior Lecturer</option>
<option id="Lecturer">Lecturer</option>
</select></td>
</tr>
<tr>
<td class="style2">
Department</td>
<td class="style3">
<select id="Select2" name="D2">
<option id="CSE">CSE</option>
<option id="IT">IT</option>
<option id="ECE">ECE</option>
<option id="EIE">EIE</option>
<option id="MECH">MECH</option>
<option id="MCA">MCA</option>

</select></td>
</tr>
<tr>
<td class="style2">
Basic</td>
<td class="style3">
<input id="Text2" name="txtBasic" type="text" /></td>
</tr>
<tr>
<td class="style2">
Grade Pay</td>
<td class="style3">
<input id="TextGrade" name="txtGrade" type="text" /></td>
</tr>
<tr>
<td class="style2">
DA</td>
<td class="style3">
<input id="Text3" name="txtDA" type="text" /></td>
</tr>
<tr>
<td class="style2">
HRA</td>
<td class="style3">
<input id="Text4" name="txtHRA" type="text" /></td>
</tr>
<tr>
<td class="style2">
IT</td>
<td class="style3">
<input id="Text5" name= "txtIT" type="text" /></td>
</tr>
<tr>
<td class="style2">
Mediclaim</td>
<td class="style3">
<input id="Text6" name="txtMedi" type="text" /></td>
</tr>

<tr>
<td class="style2">
&nbsp;</td>
<td class="style3">
<input id="Submit1" type="submit" value="submit" /></td>
</tr>
<tr>
<td>

</td>
</tr>
</table>
&nbsp;</td>
</tr>
</table>
&nbsp;</p>

</form>
</body>
</html>
import PayrollBean.PayrollSessionBeanRemote;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.ejb.EJB;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.sql.*;

public class PayrollServlet extends HttpServlet {


@EJB
private PayrollSessionBeanRemote payrollSessionBean;

protected void processRequest(HttpServletRequest request, HttpServletResponse


response)
throws ServletException, IOException, SQLException {
response.setContentType("text/html;charset=UTF-8");
PrintWriter out = response.getWriter();
String name,desg,dept;
double basic,gradepay,hra1,it1,medi;
int da1;

//Database connection
Connection dbcon;

try{
//load JDBC ODBC Bridge
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
dbcon=DriverManager.getConnection("jdbc:odbc:SalaryDSN",
"sa", "123456789");
} // end try
catch(ClassNotFoundException e)
{
System.out.println("Jdbc odbc bridge not found");
return;
}
catch(SQLException e)
{
System.out.println("Sql execption thrown in init");
return;
}
try {

out.println("<html>");
out.println("<head>");
out.println("<title>Servlet PayrollServlet</title>");
out.println("</head>");
out.println("<body>");
out.println("<h1>Servlet PayrollServlet at " + request.getContextPath () +
"</h1>");

//Get the Data from JSP Page


name=request.getParameter("Name");
desg=request.getParameter("D1");
dept=request.getParameter("D2");
basic=Double.parseDouble(request.getParameter("txtBasic"));
gradepay=Double.parseDouble(request.getParameter("txtGrade"));
da1=Integer.parseInt(request.getParameter("txtDA"));
hra1=Double.parseDouble(request.getParameter("txtHRA"));
it1=Double.parseDouble(request.getParameter("txtIT"));
medi=Double.parseDouble(request.getParameter("txtMedi"));

//Invoke EJB Methods


double daEJB=payrollSessionBean.DA(basic, gradepay, da1);
double grossEJB=payrollSessionBean.Gross(basic, gradepay, daEJB, hra1);
double pfEJB=payrollSessionBean.PF(basic, gradepay, daEJB);
double totded=payrollSessionBean.Totded(pfEJB, it1, medi);
double netEJB=payrollSessionBean.net(grossEJB, totded);

//Print the Output


out.println("<h1>name= "+name);
out.println("<h4>Designation= "+desg);
out.println("<h4>Department= "+dept);
out.println("<h4>Basic= "+basic);
out.println("<h4>Grade= "+gradepay);

out.println("<h4>DA="+daEJB);
out.println("<h4>PF Amount= "+pfEJB);
out.println("<h4>Gross Amount= "+grossEJB);
out.println("<h4>NET Amount= "+netEJB);
Statement stat1=dbcon.createStatement();
int RowInsert=stat1.executeUpdate("Insert into
Salarymas(Name,Designation,Department,Basic,Gradepay,DA,HRA,PF,IT,Mediclaim,Gr
osspay,Netpay) values('" +name +"','" +desg +"','" +dept +"'," +basic +"," +gradepay +","
+daEJB +"," +hra1 +"," +pfEJB +"," +it1 +"," +medi +"," +grossEJB +"," +netEJB +")");
if(RowInsert==1)
out.println("<h1>Data is inserted successfully= "+RowInsert);
else
out.println("<h6>Data is not inserted successfully= "+RowInsert);

out.println("</body>");
out.println("</html>");

}
catch(Exception e)
{
e.printStackTrace();
}
try{

Statement stat=dbcon.createStatement();
// Query for database
ResultSet EmployeeRS=stat.executeQuery("SELECT * from Salarymas");
out.println("<html>");
out.println("<body>");
out.println("<head>");
out.println("<title>Salary database</title>");
out.println("</head>");
out.println("<body>");
out.println("<h3>Employee list</h1>");
out.println("<table border=1>");
out.println("<tr><th>Name</th>");
out.println("<th>Designation</th>");
out.println("<th>Department</th>");
out.println("<th>Basic</th>");
out.println("<th>Grade Pay</th>");
out.println("<th>DA</th>");
out.println("<th>HRA</th>");
out.println("<th>PF</th>");
out.println("<th>IT</th>");
out.println("<th>Mediclaim</th>");
out.println("<th>Gross</th>");
out.println("<th>Net Pay</th></tr>");
while( EmployeeRS.next( ) )
{
out.println("<tr><td>"+EmployeeRS.getString("Name")
+"</td><td>"+
EmployeeRS.getString("Designation")+"</td><td>"+
EmployeeRS.getString("Department")+"</td><td>"+
EmployeeRS.getString("Basic")+"</td><td>"+
EmployeeRS.getString("Gradepay")+"</td><td>"+
EmployeeRS.getString("DA")+"</td><td>"+
EmployeeRS.getString("HRA")+"</td><td>"+
EmployeeRS.getString("PF")+"</td><td>"+
EmployeeRS.getString("Mediclaim")+"</td><td>"+
EmployeeRS.getString("IT")+"</td><td>"+
EmployeeRS.getString("Netpay")+"</td><td>"+
EmployeeRS.getString("Grosspay")+"</td></tr>");
}//end while
out.println("</table>");
out.println("</body>");
out.println("</html>");

} //end try
catch(Exception e)
{
e.printStackTrace();
}

@Override
protected void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
try {
processRequest(request, response);
} catch (SQLException ex) {
Logger.getLogger(PayrollServlet.class.getName()).log(Level.SEVERE, null, ex);
}
}

@Override
protected void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
try {
processRequest(request, response);
} catch (SQLException ex) {
Logger.getLogger(PayrollServlet.class.getName()).log(Level.SEVERE, null, ex);
}
}
@Override
public String getServletInfo() {
return "Short description";
}// </editor-fold>

EJB Coding : PayrollSessionBeanBean.java

package PayrollBean;
import javax.ejb.Stateless;
@Stateless
public class PayrollSessionBeanBean implements PayrollSessionBeanRemote,
PayrollSessionBeanLocal {

public double DA(double basic, double grade, int DAper) {


return(((basic + grade) * DAper) / 100);
}

public double PF(double basic, double grade, double DAAmt) {


return (((basic + grade + DAAmt) * 12) / 100);
}

public double Gross(double basic, double grade, double DA, double HRA) {
return (basic+grade+DA+HRA);
}

public double Totded(double pf, double it, double mediclaim) {


return (pf+it+mediclaim);
}

public double net(double gross, double totded) {


return (gross-totded);
}
Output

You might also like