Currently I’m getting data in jsp using scriptlet but now want to use JSTL so I’m trying to convert my scriptlet code to JSTL. But for following scenario I don’t know how to get data in jstl.
Let me explain by example:
There are 3 objects
- User (user_id, username, password)
- Box (box_id, box_name,list_of_boxCat)
- BoxCat (box_cat_id,box_id,user_id,cat_name)
Now I need to display list of boxes a user own. So i have created a list of Box objects by firing query in servlet and pass that list in jsp in request attribute then access it in jsp. Until this everything goes fine. But now I have to access BoxCat object which do not have any reference from Box object directly. To get BoxCat object I have to combine Userid and Box id and then I can get BoxCat id. So in scriptlet I call my DAO and get list by running query. But I don’t know how to do this JSTL. Anyone please help me on how to do this?
You should redesign or map your model so that it suits whatever your view needs. Does the view need a
List<BoxCat>as a property ofUseror maybeBoxCatas a property ofBox? If so, then make that so and change your controller and DAO to fill that beforehand.Otherwise you will end up in clumsy and potentially memory-inefficient workarounds using a mapping of the entities by their ID such as
Map<Long, Entity>.