• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Include code in JSP

 
Ranch Hand
Posts: 99
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have about 20 JSP pages and each has three parts
Part1
Part2
Part3
Here Part2 is the JSP specific code that differs fron JSP to JSP
Part1 and Part3 are the common piece of codes that are same in all the JSPs, so here we are separating the codes Part1 and Part3, keeping them in two different JSP pages and including them in the main JSP page. Now this is working fine.

My 1st doubt is,
I want to keep Part1 and Part3 in a single file and include this at those places without affecting the functionality, can this be achieved?

Here while including the files in the JSP, in this case do i have to use the include directive(<%@include%>) or standard JSP include(<jsp:include>) ? Which one do i have to use?
 
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Sounds like the perfect use of a tag file.
 
Bharadwaj Adepu
Ranch Hand
Posts: 99
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Sorry, i didn't get you Bear!!
 
Ranch Hand
Posts: 1374
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Bharadwaj Adepu wrote:I want to keep Part1 and Part3 in a single file and include this at those places without affecting the functionality, can this be achieved?


Why do you wanna do that? Keep header(part1), footer(part3) in separate files. and develop body(part2) file for every page and include header and footer into them.

But I think you want header and footer in one file and want to include body dynamically. Is it? It would be ugly.

And IMO bear has suggested custom tag. but it's not worth the effort. You can create one custom tag with one attribute name file/page and pass the name of the file there. And rest of the things will be handled by custom tag. I would still suggest the first way.
 
Bear Bibeault
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Vishal Pandya wrote:And IMO bear has suggested custom tag. but it's not worth the effort. You can create one custom tag ...


So you say that creating a custom tag is "not worth the effort" and then suggest creating a custom tag? Ummm...

In any case, this is incredibly easy using a tag file to supply the common header and footer. Each page would then simply look like this:



Passing URLs to a tag would be incredibly burdensome and unnecessary.
 
Vikas Kapoor
Ranch Hand
Posts: 1374
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have changed my thought bear. Actually I have seen very few custom tag implementation for eg. a tag for creating a table and fill it with data as per its attribute values and much more. So I thought custom tag should be used when very complex logic is going on.
 
Bear Bibeault
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Vishal Pandya wrote:So I thought custom tag should be used when very complex logic is going on.

Custom actions can be used for everything from the very simple to the very complex. And for markup-centric usage, such as this topic, a tag file is not only easy, but elegant.
 
Ranch Hand
Posts: 80
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
i think there is some confusion between tag files and custom tags.
 
Bear Bibeault
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Such as? They're just two mechanisms to create custom actions.
 
Politics n. Poly "many" + ticks "blood sucking insects". Tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic