Although all server side components provide the option of including file like <jsp:include> etc, having a way to include files using clients side script can come handy if the pages are made of plain old HTML.
We provide a code for explaining how Jquery can be used to include files.
Main file:
Include file:
The jquery load function basically is an AJAX call which loads the content and inserts it into the div with id=include.
The load used uses the three parameter function. The first parameter being the URL, second is data (which is basically a key/value pair object) and lastly a function. The data (key/value) gets passed to the URL as parameters. The include file can access the parameters like any GET parameters received.
Add both the files in a Java application server context. The files should be placed in same directory. Access the main file from browsers using a localhost url for going through the application server.
See the contents loaded from include file and also the parameter contents received in the include file.
(0 Votes)




