Win a copy of Svelte and Sapper in Action this week in the JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Bear Bibeault
  • Junilu Lacar
Sheriffs:
  • Jeanne Boyarsky
  • Tim Cooke
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • salvin francis
  • Frits Walraven
Bartenders:
  • Scott Selikoff
  • Piet Souris
  • Carey Brown

JSP fragments

 
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
 
Marshal
Posts: 67451
173
Mac Mac OS X IntelliJ IDE jQuery Java
  • 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
 
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
 
    Bookmark Topic Watch Topic
  • New Topic