• Post Reply Bookmark Topic Watch Topic
  • New Topic

how to design this app . JSP include problem  RSS feed

 
li bei
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Ranchers.
I have 3 jsp files, they are not full page to view,but they are use to included into other jsp files. I call them chips. The 3 chips all have to access the database.

Here the question is ,I have many jsp files wants to include the 3 chips.And I don't want to write database accessing code in the jsp file. So where should I write the database accessing code ?

Thanks in advance.
 
li bei
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for your reading my words.
Maybe I haven't described it clearly.Let us take an example:
suppose I have 5 actions named action1,action2,action3,action4 and action5. They forward to jsp1,jsp2,jsp3,jsp4,and jsp5. The 5 jsps all have to include 3 chips(chip1,chip2,chip3) as parts.
If I query the data which chips need in action1-5, that is a bad design,because if one of the 3 chips have to be changed ,I have to modify all the 5 actions.

I have tried to write 3 actions name chipaction1,chipaction2,chipaction3,they query the data ,and then forward to chip1,chip2,and chip3,then include the url-patterns in jsp1-5,but that seems doesn't work.

I really wonder the best design.
Thanks in advance.
 
subodh gupta
Ranch Hand
Posts: 203
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Can you tell me what your chips are doing?
 
li bei
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This application is about clubs.
One chip shows the new members in the current club,
one shows the new songs shared ,
one show the new pictures uploaded, and so on...
 
mohit bahl
Ranch Hand
Posts: 48
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi li bei

So if I understand it correctly your 3 chips require to show something which needs to access the DB. Now as known writing DB access logic in jsp is not a very good practice. Also what I feel is that you have created these chips because showing new members in the current club, showing the new songs shared and showing the new pictures uploaded, are part of almost all the JSPs.

In my opinion the solution will require the following three things to be done

What you can do is put this logic of fetching the data for these 3 chips in a POJO which will be either be called from all the actions or you can device a post processing filter for doing this.

Once the data is received from the POJO put the data into 3 different objects (device the classes for these objects as per the properties required to be shown on the front end, this class will basically be a bean) and embed these beans in the request (by the action class or filter as you plan to do it).

And finally on the presentation layer modify your chips to (using JSTL or struts tags) extract these embedded objects from the requests and display the properties as you require.

let me know if this helps or if you have more queries

cheers!
mohit
 
li bei
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you.
I am sure your solution will be help.
But if I embed these beans in the request by the actions ,I have to modify all the actions when one of the chips' requirement changed ,isn't it?
I can resolve the problem whith your help now . I am wondering a even perfect way. Is there one ?
 
mohit bahl
Ranch Hand
Posts: 48
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi li bei

i have already provided the solution for the same in my response, go for the post processing filter. so after each request is handled by the action the filter will do the data fetching and embedding it in the request for your chips.

let me know if it is still not clear.

cheers!
mohit
 
li bei
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
ah~ The filter is a good idea.
I'll try that.
Thanks.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!