• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How to do group by in a jsp

 
Omar Ali
Ranch Hand
Posts: 33
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello All,

I am having difficulties while doing the grouping in a jsp.

I am having a table which is retrieving the employee No., Directorate. The directorate name is coming duplicate as it is retrieved from the DB.
My jsp is displaying:
111 IT
222 IT
333 IT
So, I want it in the jsp as:
IT
111
222
333
Can you please help.
 
Devaka Cooray
ExamLab Creator
Marshal
Pie
Posts: 4690
337
Chrome Eclipse IDE Google App Engine IntelliJ IDE jQuery Postgres Database Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This is not something you should do right in the JSP. You can make a list of employees for each directorate from somewhere in your business classes, and make your controller to set a request attribute carrying the list of directorates. Here, each directorate object should either contain or mapped to a list of corresponding employee objects. From the JSP, you can iterate over this directorates list using forEach tag of the JSTL core library. At each iteration, you can have another (nested) forEach iteration to iterate over the corresponding employee objects.
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 65229
95
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Move any Java code out of the JSP. Putting JSP code in modern JSP is a poor practice and downright irresponsible at this stage.

I've moved this to the JDBC forum because it's not about JSP.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic