Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Include code in JSP  RSS feed

 
Bharadwaj Adepu
Ranch Hand
Posts: 99
  • Mark post as helpful
  • send pies
  • 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?
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 65826
134
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • 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
  • Quote
  • Report post to moderator
Sorry, i didn't get you Bear!!
 
Vikas Kapoor
Ranch Hand
Posts: 1374
  • Mark post as helpful
  • send pies
  • 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
Author and ninkuma
Marshal
Posts: 65826
134
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • 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
  • 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
Author and ninkuma
Marshal
Posts: 65826
134
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • 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.
 
gurneeraj singh
Ranch Hand
Posts: 80
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i think there is some confusion between tag files and custom tags.
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 65826
134
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Such as? They're just two mechanisms to create custom actions.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!