Thursday, October 8, 2009

Ways to include a file in another file

  1. SSI
    Enable SSI in your sever. Then use the following to include one file
    • <!--#include virtual="filename" -->
    • <!--#include file="filename" -->

  2. Include Directive
    <%@ include file="filename" %>

  3. jsp:include Element
    <jsp:include page="filename" />

  4. iframe
    <iframe src="filename" style="height:100%;width:100%;frameborder:0;scrolling:no"> </iframe>


NB: "filename" includes the relative path of the file (with respect to the file that contains include statement) & the filename with its extension (ex. /incl/header.html).

SSIs are a workable solution for including different types of content in your Web site or Web application, but they're not the best choice for Java developers. Not only does JavaServer Pages technology provide an all-Java alternative to SSIs, but the two technologies aren't easily combined. JSP pages end in the extension .jsp, which means that for SSI directives to work you have to either change your SSI configuration to also parse JSP files (adding overhead to every JSP page parse), or change your JSP configuration to treat the .shtml extension as a JSP page (which is a bad idea). JSP technology is the best content management solution for Java developers, and fortunately its include mechanism is a snap to learn.

1 comment:

  1. The top opens an fstream with the default parameters through the constructor of an fstream, and the bottom simply opens it separately (with possibly different parameters). They are both fine, but generally you should try to use the constructor to do the creation of the object instead of doing it separately.

    vitamine k

    ReplyDelete