Howdy all, Quick question; I am struggling to seperate jsp/bean functionality. Here's the scenerio: I need to build a small app that displays organizations and their members. The organization names should not be "hard coded" in the jsp page; instead it should retrieve this from the db like all member data. This would allow for an organization and its members to be removed from the db and be reflected in the app. Easy so far. However, I am noticing that there is a lot of logic cluttering the jsp, while most of the grunt work of placing the data in a vector is handled by the bean and then handed to the jsp for further processing and display. Are there any strategies for decoupling situations like these where presentation and logic are tightly entangled? I can provide some code if this would help clear up the situation. Although, I'm not looking for an easy out (code), rather an approach to solve this myself. Please advise.
I am newbie too, but my first idea would be to use a servlet because the databasehandling is nicely described in tutorial's and even better in the blueprint of their (Sun's) 'petshop ecommerce' example.
Howdy Tim, Quick response! Think about this: A schema with three layers: 1. Data Base Access: Classes encapsulating the tables of the DB with methods get/setProperties (which correspond with the columns of the table), a create and destroy method to insert o delete a new record in the table and (statics) methods implementing the functionality that you need from the Middle layer and the Presentation layer... 2. Middle layer This layer connect the Presentation layer with the DB layer. It consist in a class or a set of classes with static methods which you invoke from the Presentation layer (jsp files). The point is to separate the DB access from the Logic. So if you change the DB you only have to change the DB driver in the DB layer. 3. Presentation layer (JSP Files) In the JSP files you have to use beans from the Middle layer and from the DB layer. The beans from the middle layer are used to connect with the DB layer and the DB and to handle the most of the Logic. The beans of the DB layer are used as auxiliary objects whose properties take the values of the DB record. In the Presentation layer you use objects of the DB classes and when you need to connect with the DB, objects or request to the middle classes as argument of its methods. If you don�t understand this response or need anything more write me.