I'am making a dynamic website in which the positioning and components of certain components like the fixed header, menubar, footer etc are common in almost all the pages. So how do I include this fixed components in my every webpage? I'am using JSP and javascript. Thanks in advance.
-
3http://stackoverflow.com/questions/9110148/include-another-jsp-file – Ankit Tyagi Dec 13 '13 at 04:36
3 Answers
If you are including static content then you can use
<%@include file="includes/header.html" %>
or for dynamic content
<jsp:include page="includes/header.jsp" />

- 44,617
- 6
- 35
- 64
From http://docs.oracle.com/cd/E19159-01/819-3669/bnajb/index.html:
Reusing Content in JSP Pages
There are many mechanisms for reusing JSP content in a JSP page. Three mechanisms that can be categorized as direct reuse are discussed here:
The include directive
Preludes and codas
The jsp:include element
An indirect method of content reuse occurs when a tag file is used to define a custom tag that is used by many web applications.
The include directive is processed when the JSP page is translated into a servlet class. The effect of the directive is to insert the text contained in another file (either static content or another JSP page) into the including JSP page. You would probably use the include directive to include banner content, copyright information, or any chunk of content that you might want to reuse in another page. The syntax for the include directive is as follows:
<%@ include file="filename" %>
For example, all the Duke’s Bookstore application pages could include the file banner.jspf, which contains the banner content, by using the following directive:
<%@ include file="banner.jspf" %>
Another way to do a static include is to use the prelude and coda mechanisms described in Defining Implicit Includes. This is the approach used by the Duke’s Bookstore application.
Because you must put an include directive in each file that reuses the resource referenced by the directive, this approach has its limitations. Preludes and codas can be applied only to the beginnings and ends of pages. For a more flexible approach to building pages out of content chunks, see A Template Tag Library.
The jsp:include element is processed when a JSP page is executed. The include action allows you to include either a static or a dynamic resource in a JSP file. The results of including static and dynamic resources are quite different. If the resource is static, its content is inserted into the calling JSP file. If the resource is dynamic, the request is sent to the included resource, the included page is executed, and then the result is included in the response from the calling JSP page. The syntax for the jsp:include element is:
<jsp:include page="includedPage" />
The hello1 application discussed in Packaging Web Modules uses the following statement to include the page that generates the response:
<jsp:include page="response.jsp"/>
So you may use
<jsp:include page="includepage.jsp" />

- 14,987
- 4
- 32
- 49
-
Copied without attribution from http://docs.oracle.com/javaee/1.3/tutorial/doc/JSPIntro8.html – Pekka Jan 05 '14 at 06:06
-
-
As said, it is not acceptable to just copy sources verbatim, even if you link to them. You are expected to come up with an answer on your own. – Pekka Jan 05 '14 at 06:12
-
hey my edit limit is over..can you please edit my post with the link..!! – Sajad Karuthedath Jan 05 '14 at 06:12
-
I edited it in, but the post may still end up getting deleted altogether by a moderator because the quote is the only thing in the post. In the future, really don't do that any more. – Pekka Jan 05 '14 at 06:14
-