How can I get the average salary of all employees in the selected company? I first select the company and then pass the id and based on that id, i get all employees in there and
You could sum the salaries up and then divide by the number of employees:
<% List employees = company.getEmployees();
double sum=0.0;
%>
ID
Name
Salary
<%
for(int i=0; i
<%=employees.get(i).getId()%>
<%=employees.get(i).getNom()%>
<%=employees.get(i).getSalary()%>
<% } %>
//get the average salary of all employees
Average salary of all employees in this company:<%=sum/(double)employees.size()%>
Having said that, I urge you to reconsider before going down that road. Having code inside your JSP will severely hinder your chances of maintaining it if it gets any bigger than 1-2 pages. All your business logic should happen in your code (e.g. inside your servlets) and in JSPs only display the information.