• Post Reply Bookmark Topic Watch Topic
  • New Topic

any tag for adding objects

 
joseph prabhu
Ranch Hand
Posts: 162
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
joe here


my code is



The above code gives the output;

my question is instead of creating the object for LinkedList and add objects
in it then reqeust.setAttribute("list",li);
is there any tag in jsp for shortcut. we use <jsp:useBean></useBean> for usebean
 
Steve Luke
Bartender
Posts: 4181
22
IntelliJ IDE Java Python
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
No, there isn't a tag for that. The reason is this is work that shouldn't really be done in the JSP. The JSP should be about displaying data, not performing logic.

So that functionality should be mover - usually to a controller servlet that gets called before the JSP, but can also be moved into a JavaBean. For example:



The idea is that your JSP doesn't really do any work. Ideally, you have a controller servlet that decides what data needs to be made available to the JSP, the servlet generates it (or has some other data object generate it) and then makes it available to the JSP.

But, barring a refactoring of your entire code base to MVC, using a dummy JavaBean to do your work increases the separation of the display from the Model, and will make it easier to do that transition later on.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!