How to include one HTML file into another? - html

I have tried every possible question here on stackoverflow but unable to resolve this issue ...
<!--#include virtual="include.shtml"-->
<!--#include virtual="include.html"-->
<!--#include file="include.shtml"-->
<!--#include file="include.html"-->
<!--#include virtual="/include.shtml"-->
<!--#include virtual="/include.html"-->
<!--#include file="/include.shtml"-->
<!--#include file="/include.html"-->
<? include("/include.shtml"); ?>
<? include("include.shtml"); ?>
<? include("/include.html"); ?>
<? include("include.html"); ?>
I tried with apache server running at localhost/include/index.html or file:///home/sahil/Desktop/include/index.html with all above includes but none of them is working for me :( .Now which method should i use to include one HTML file into another , considering my index.html and include.html both are in same directory ???

The former syntax is SSI, the latter is PHP. Both are server technologies and will only work if accessed from an HTTP server that supports and is configured to check the file for the syntax (which usually means you have to turn the support on and use a .shtml/.php file extension (or change the config from the default to determining which files to check)). Other server side technologies are available.
The only "include" mechanisms in HTML itself are (i)frames and objects.
You could also consider a template system such as TT that you could run as a build step to generate static HTML documents (NB: TT can also be used on the fly).

HTML is Static
It is not possible to include a HTML page within another HTML page with static HTML because it is simply not supported by HTML. To make your HTML dynamic, you have 2 possibilities: use a client side script or use a server side technology.
...Unless you start using frames (dropped with the HTML5 standard) or iframes that are most likely not a solution because of the fact that it is treated as a completely different web page.
Client Solution
You could create a JavaScript file and write your HTML with the document.write function and then include the JavaScript file where ever you need it. Also, you could use some AJAX for this, but there are JavaScript libraries out there that could ease your burden such as the popular jQuery library.
Yet, I would not suggest using a client solution because it is more trouble than it is worth...
Server Solution
There are many server side solutions out there: ASP, ASP.NET, ASP.NET MVC, Java, PHP, Ruby and the list goes on. What you need to understand is that a server a side technology could be described as a parser for a specific server side language to automate certain tedious tasks and to perform actions that would represent a security risk on the client.
Of course you will need to have the means to host such a site and to configure the hosting environment. For example, you could host a PHP website with Apache and even have a developer hosting environment such as /MAMP/LAMP/WAMP.
You can view an example of including a page in PHP in the online documentation.
Personally, I would be more inclined to use a server side solution.

HTML doesn't have an 'include' mechanism - I'm not sure where you've seen these solutions on StackOverflow. You've probably been looking at answers for a server side language such as PHP or ASP.
You do have the following options for 'pure' HTML where you only have static pages and JavaScript:
Frames
Ajax
See my answer here for sample code and more details (and also a caveat about SEO if that matters to you).

Make your html file you want to include to php file. (only change the extension - to .php). If the files are in one directory, include code is:
<?php include "nameoffile.php" ?>

Related

How to show list of web server files in HTML

I want to show list of all files from web server or a directory from web server into my WEB page using HTML.
I searched google a lot but didn't find anything.
Any suggestions?
Possibility 1) activate DirectoryBrowsing [aka DirectoryListing] (Apache, IIS and probably all others support this).
Possibility 2) use PHP, JSP, ASP or whatever language to make a list of the files.
HTML itself is just a markup language, so there's no possibility to do that with HTML only.

Difference in opening a file directly and uploading to a web server

Given a simple HTML file is there any difference when testing, in opening it directly by double clicking it or uploading to IIS/Tomcat and accessing localhost/simpleHTML?
In the case of html files it dosenot matter much. Where this matters is when the page is made in languages like php, jsp etc. A webpage containing php or jsp files will not be detected by browsers when directly opened. For this we use webservers like wamp, xampp, lamp, tomcat etc and acces it via localhost/pagename. For more details just view the pagesource of a php file. You wont be able to find and php scripts in it. You will be able to see only the html part in the page. For scripting languages like html, javascript, css etc. opening directly dosent matter.
Hope this is useful to you.
No, a simple HTML-only file will not be rendered differently most(99.9%) of the time by opening it directly by double-clicking from the local file system and accessing it from a web server. The only difference will be caused if the file contains any server side language (PHP, ASP etc..)

in HTML page can we use jsp code

In page.html we can use javascript code, I accept that, but can we use jsp and tld files in html files.
Please explain.
Any server-side code would need to be executed on the server, not in the browser. There's a hard separation between the server-side processing and the client-side processing. So the JSP code wouldn't be able to interact with the JavaScript code or anything like that.
In order for server-side code to be executed in an HTML file before rendering it to the browser, your server would need to be configured to process that code. It would be a matter of configuring your web server, whichever one you're using. By default I imagine it just returns .html files to the browser without any server-side processing. But you can configure your web server to treat .html files just like it would JSP files.
Keep in mind that you would need to treat those .html files like you normally would JSP files. It would have to match the same conventions for separating client-side code from server-side code.
If you configure your web server to map the text/html content type to JSP, you can.
No. JSP pages are executed on the server side and produce HTML, which is sent to the browser. JSP acts just like PHP in this regard, essentially "rendering" some HTML code and sending it off to the user. You can't embed JSP code in the HTML and send it off to the user - their browser will just do nothing with it.

Uploading file using HTML

Can anyone show me how to create an HTML page that allows to upload files?
It will be really appreciated.
File uploads cannot be done purely in HTML. You must have some kind of server logic to process the Multipart-data from the HTML-form (by using ASP.Net, PHP or whatever).
You can't do it in pure HTML, you need a script on server side to store the file.
If you can use PHP, check the manual on handling file uploads for details.
http://www.cs.tut.fi/~jkorpela/forms/file.html
You would need some server side componenet ot store the uploaded content for you.
There are near to infinite options for that. :)
Also, you have styled File uplaod components provided by various Ajax libraries and Tool kits like DOJO ,jQuery that make it look more nice and provide various flavors to do this.

HTML Include file

I have a basic web application packaged as an EAR deployed on GlassFish.
The web module has some html files.
The html files have a common footer, an html file, that I would like to extract out and make an include.
When I do, and put:
<!--#include virtual="insertthisfile.html" -->
in an html file, it does not work.
Should this work?
This is a technique called Server-Side Includes (SSI). It may not be enabled on your web host. If it is, sometimes they force a .shtml extension to be required for included files, so try renaming your file insertthisfile.shtml.
If that doesn't work, you might be able to enable SSIs in a .htaccess file (assuming your web server is Apache). You can find instructions on how to do this by googling. There's a decent set here.
If that fails, I would contact your web host and see if they have SSIs enabled.
Should this work?
Perhaps, at some special settings, with some experienced programmer, this could be useful.
In my case the include statement seems to be ignored.
I could include some text with
(embed src="include.shtml")
(/embed)
Above, I type () instead of angular brackets.
With the "embed", the setting in the header of the page does not apply to the included text; it should be repeated again, and, by default, the result is ugly.
It looks strange, as if the designers of the html did not build-in the very basic tool, the include command. For short articles, the include could save an order of magnitude in the size of files.