aspose file tools*
The moose likes JDBC and the fly likes How to do group by in a jsp Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » JDBC
Bookmark "How to do group by in a jsp" Watch "How to do group by in a jsp" New topic
Author

How to do group by in a jsp

Omar Ali
Greenhorn

Joined: Dec 23, 2008
Posts: 15
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
Saloon Keeper

Joined: Jul 29, 2008
Posts: 3224
    
  49

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.


Author of ExamLab ExamLab - a free SCJP / OCPJP exam simulator
What would SCJP exam questions look like? -- Home -- Twitter -- How to Ask a Question
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61661
    
  67

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.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: How to do group by in a jsp