File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes JSP and the fly likes Design and include Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » JSP
Bookmark "Design and include " Watch "Design and include " New topic

Design and include

Alberto Belletti

Joined: Oct 05, 2004
Posts: 2
Well, I'm developing a website where the content is dynamically included.It's my first jsp project so I've got some - probably basic -questions.
A jsp page is divided in some areas like content, navigation etc.
Content -as an example - is dynamically included and should display some - I call them - blocks.
A block is for example an image, a list and a headline. So content can have 1 to many blocks.
So a page ->content->block->image
I'm using the MVC pattern so my first approach was that my controller servlets passes to the jsp page an object called model and the jsp page gets the data out of it.
Because of the structure this gets very ugly like:
Page onepage = (Page) model.getPage();
and then
(Area) onearea = (Area) onepage.getArea('content');
and so on...
The second problem is how do I pass the needed objects to the includes..?
Actually the jsp-page gets the object and writes it into the request with setAttribute and the included page pulls them out..
But this looks horrible..
Thanks for any advice!
Anthony Watson
Ranch Hand

Joined: Sep 25, 2003
Posts: 327
The Struts and Tiles frameworks provide a commonly used solution for the situation you describe. These frameworks are getting to be ubiquitous, so I believe that it is worth your time to learn them. If you think about it, multiple developers with years of experience and tons of community feedback are probably going to have a better MVC solution than you come up with in a short amount of time by yourself (unless you happen to be Rod Johnson). Struts isn't perfect, but I think its much better than creating your own solution.

Anthony W.<br />MCP, SCJP 1.4, SCJD, SCWCD 1.3, SCWCD 1.4, SCBCD
Alberto Belletti

Joined: Oct 05, 2004
Posts: 2
Thanks Anthony for the reply but unfortunately the project is advanced and we'd like to implement this on our own.
By the way I think it's difficult to learn a technology and also an advanced framework in the same time
But I hope someone can give me an advice how to design my approach..
I agree. Here's the link:
subject: Design and include
jQuery in Action, 3rd edition