aspose file tools*
The moose likes JSP and the fly likes Using c:import to include page elements? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » JSP
Bookmark "Using c:import to include page elements?" Watch "Using c:import to include page elements?" New topic
Author

Using c:import to include page elements?

Stefan Mohr
Greenhorn

Joined: Mar 11, 2008
Posts: 14
Hi guys,

I think I'm barking up the wrong tree here, but don't know the "right" way to go about it.

In a nutshell:
I'm creating a site with a significant amount of pages (using ICEfaces but I don't think that's relevant to my issue) and will have a navigation bar at the top of each page.
Obviously, I don't want to replicate (and maintain...) the nav bar code in each page I create, so I'm looking at how one imports page content from another page.

What I've done so far is create a separate file called Navigation.jspx. I've tried leaving it as a fully-formed page on its own, and also as a "broken" JSP document that only has the JSP code I want.
Then, in my "real" pages, I used syntax like this:


What I am hoping to happen (clearly it doesn't work this way) is that the import statement will essentially pull in all the page content of my Navigation.jspx and plop it in place in my main page, at which time Jboss will render the whole combined page.

That's my fuzzy little dream world, anyways.

Can anyone point me towards the proper mechanism for including shared content into a page? It's obviously done all over the place but I'm clearly lacking a fundamental concept in getting this to work.
Merrill Higginson
Ranch Hand

Joined: Feb 15, 2005
Posts: 4864
If you want to include the contents of the file before it is translated into a Servlet, use the <%@ include file="filename" %> directive instead of <c:import> tag.


Merrill
Consultant, Sima Solutions
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61221
    
  66

It'd be much cleaner to use a custom tag -- which in JSP 2.0, is almost trivially easy to set up. (Hint: tag files).
[ March 18, 2008: Message edited by: Bear Bibeault ]

[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Stefan Mohr
Greenhorn

Joined: Mar 11, 2008
Posts: 14
Thanks Merrill and Bear both!

My initial errors I was seeing were due to ICEfaces getting upset about using a static jsp include on a jspx file.

I'm doing a little research into tags and it looks like a graceful way to go about it - thanks!
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Using c:import to include page elements?