• Post Reply Bookmark Topic Watch Topic
  • New Topic

JSP fragments  RSS feed

 
Rick Peifer
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I'm trying to understand jsp fragments, or jsp at general actually. I'm trying to design a system in which pages can be build with various building blocks. Ideally each of these blocks act completly independent of one another. However as I understand JSP fragments, there is no way to prevent different blocks (fragments) from interfering with each other if they decide to use the same variables names.
Can anyone tell me if my assumption is correct? If so, is there another solution than just make sure that the names are different?

Thanks!
Rick
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 65833
134
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes, all "blocks" on a JSP page will share the same page context and therefore the same scopes. You can always try the time-tested approach of name-spacing. E.g. all scoped variables created by logical construct "fred" are named fred.this or fred.that or fred.theOtherThing.

This assumes that you are talking about JSP 2.0 and scoped variables accessed by the EL. If you are still using old-fashioned scriptlets.... well, don't.
 
Rick Peifer
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Bear,

I figured as much, but I hoped that I had missed something somehow. The system I'm designing people may put more blocks on one page, even if that means that the very same block is being used more than just once on the very same page. In such a case using namespacing would not work anymore.
Also other people may create new blocks to be used on a page, I really wanted to find something which didn't need to force extra rules upon these people, because they will probably be broken anyway.
Thanks for your help, it still helped a lot!

Rick
 
Pedro Erencia
Ranch Hand
Posts: 70
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can use jsp actions include and forward. In that case different blocks will be different servlets. This is the tiles approach, i.e.
check apache tiles
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!