HTML <meta> tag - html

I am reading a Servlet "HellowWorld" tutorial. The servelet is defined in a HelloWorldServelet.java class. Super simple to output "Hell world" message to the client request. The only html file is "index.html" below. I don't understand how the meta tag works. As I run the application in the web server, it automatically this page with the URL:
http://localhost:8080/helloworld/HelloWorld
How the attributes "http-equiv" and "content" work together with the servelet?
<html>
<head>
<meta http-equiv="Refresh" content="0; URL=HelloWorld">
</head>
</html>

The Refresh meta-tag automatically redirects the browser to the URL given after the specified amount of time.
Without seeing the tutorial you are using, I can't imagine why you would need to use it for your task.
https://en.wikipedia.org/wiki/Meta_refresh

"http-equiv" and "content"
they are used for adding message headers in http response .
For example http-equiv can be used to refresh the page.
if you specify something like this
<meta http-equiv="refresh" content="45">
you are instructing browser to refresh in every 45 seconds.
Other than refresh,you can use it to set cookies and etc.

Related

html cache-control=no-cache changes to cache-control=max-age=0

I've built a simple page to test the cache-control and I'm getting confused by the results.
The page is just
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title>Website teste</title>
<meta http-equiv="cache-control" content="no-cache">
</head>
<body>
<div>Hello World</div>
<script>
setTimeout(function () {
window.location.reload()
}, 10000)
</script>
</body>
</html>
If I do a hard-refresh the cache-control is what expected
but the next refresh the cache-control changes to max-age=0
And shouldn't the result be a 304 (Not Modified) instead a 200 (OK)
This sample site is running on VisualStudio (IIS)
The http-equiv attribute of the meta element is defined in the HTML standard. Note that:
The http-equiv attribute is an enumerated attribute. The following table lists the keywords defined for this attribute...
cache-control is not one of the listed values, and thus this directive has no effect.
Your assumption isn't unreasonable, though; in earlier versions of the standard it was suggested that servers could create headers based on this element:
HTTP servers may read the content of the document <HEAD> to generate
header fields corresponding to any elements defining a value for the
attribute HTTP-EQUIV. NOTE - The method by which the server extracts document meta-information is unspecified and not mandatory.
I have no idea whether any servers actually did this, though.
Finally, note that the Cache-Control header you're looking at in the developer tools is a request header, not a response header, and thus has nothing to do with any of this. It's something that browsers often add to the request on refresh to make sure they don't get served cached content.

Can we add http response headers directly into html pages

I need to add response headers like X-Frame, Cache-control, Pragma etc directly into the html code, may be, using attributes in html elements?
It is for help pages which are directly coming from a directory via href link.
Is there any way to add headers to these htmls?
You can use meta to replicate some of these. Normally not the ideal solution, but look into the http-equiv attribute of meta tags. I believe a lot of these have been deprecated in newer browsers.
Examples:
<meta http-equiv="Cache-control" content="no-cache"/>
<meta http-equiv="X-Frame-Options" content="sameorigin"/>
<meta http-equiv="pragma" content="no-cache"/>
In short: no, you cannot. HTML files are the body of an HTTP response; the headers must come from the server. Anything you could embed in the HTML file would just become part of the body.
You can add something like this, if php execution is enabled on your web server:
<?php
http_response_code(your_response_code)
?>
rest-of-your-html-code
This will execute a php script that will set the response code.

Why does Chrome not redirect using meta refresh

An application that I work with has a PL/SQL package that creates a page and uses a function to create META tags.
It creates a webpage with a META tag exactly like this :
<META HTTP-EQUIV="Refresh" NAME="Refresh" CONTENT="1; URL=PaymentSubmit.html">
The problem is that Chrome does not like the NAME="Refresh" attribute. It does not redirect the page, although it does redirect properly in IE and Firefox
If I remove the NAME attribute, so that it looks like this it works in all browsers :
<META HTTP-EQUIV="Refresh" CONTENT="1; URL=PaymentSubmit.html">
What's going on here? I can't find a W3C standard for META redirect, so does every browser make up it's own rules ? I'm not sure if it ever worked in Chrome, but since I never heard any bug reports I assume it used to work in Chrome.
Anyone have a similar problem ?
Thanks
If you check the w3c wiki you can find the following quote:
Exactly one of the name, http-equiv, and charset attributes must be specified.
It mean's it is not valid html that both - name and http-equiv attributes are set.
Read this W3C's HTML and XHTML Techniques test on meta refresh:
Find all meta elements in the document. For each meta element, check
if it contains the attribute http-equiv with value "refresh"
(case-insensitive) and the content attribute with a number greater
than 0 followed by ;'URL=anyURL' (where anyURL stands for the URI that
should replace the current page).
The behavouir of the other browsers is not wrong, but chrome is more strict.
More details about the correct behavouir - and the valid reference - are available at http://www.w3.org/TR/html5/document-metadata.html#attr-meta-http-equiv-refresh
As far as browser support:
The support for <meta> refresh is there even in IE6
The syntax to be used is:
Place inside <head> to refresh page after 5 seconds:
<meta http-equiv="refresh" content="5">
Redirect to http://example.com/ after 5 seconds:
<meta http-equiv="refresh" content="5; url=http://example.com/">
Redirect to http://example.com/ immediately:
<meta http-equiv="refresh" content="0; url=http://example.com/">
If you plan to support javascript disablers (Which I don't think you should do :)
Do this:<noscript><meta http-equiv="refresh" content="0; url=url here"></noscript>
It is not a part of HTTP standard.
However, there are alternatives:
For refreshing the page after 5 seconds, do the below:
<body onload="javascript:setTimeout(function(){ location.reload(); },5000);">
If you want to redirect after 5 seconds, then do the below:
<body onload="javascript:setTimeout(function(){ window.location = 'http://example.com';},5000);">
If you want to redirect immediately:
<body onload="javascript:window.location='http://example.com'">
But there isn't any alternative for javascript disablers (yippee!!)
Conclusion:
So, my suggestion, would be to use my javascript alternatives, because they are not going to be replaced.
But <meta> refresh tag may be discontinued in the coming years.
More reading : http://en.wikipedia.org/wiki/Meta_refresh
For the <META tags, Microsoft has published specific guidelines:
Page and site guidelines for SEO
Specifically, for the <meta http-equiv="refresh"> element, Microsoft states the following:
A page redirect should provide both a message with the new page location and sufficient time for users to read the message. A page redirect with a time-out period of less than five seconds may result in a lower search-engine ranking.
To redirect a page, consider using an HTTP redirect instead. An HTTP redirect is more likely to transfer the authority of the old page to the new page.
Personally, instead of a <meta refresh tag, I would recommend you use a 301 Redirect. In PHP you could do, for example, the following:
<?php
header("HTTP/1.1 301 Moved Permanently");
header("Location: http://www.yourdomain.com/newpage");
?>
This method is better than the <meta refresh because usually a 301 redirect includes the address to which the resource has been moved. Web browsers will typically follow 301 redirects to the new location automatically, without the need for user action.
According to some definitions of 301 Redirect, it would even preserve old positions:
A 301 redirect should be used whenever a website is moved to a new domain name (URL) so that search engines will quickly change their indeces and, in theory, preserve the search engine rankings that the site had at the previous domain.
All this is in line with the fact that many shady websites use <meta refresh to open unwanted websites (spam/ advertisements etc.). Hence I would conclude that the refresh meta tag should not be used.
For the other meta tags, please read the following: 18 meta tags every webpage should have.
Keep in mind that not all meta tags are of crucial importance; for example, Google says it does not use the keywords meta tag in web ranking.
But remember: it is Better to have, and not need, than to need, and not have.
Just don't use the <META refresh ;)

html meta tag, avoid browser url change

i have the following url in my jsp page of my spring mvc app, my controller froward to the a jsp which has the following:
<meta http-equiv="refresh" content="0;URL='/app/static/test'"
this causes the the page to load correctly, however the browser url changes.
Is it possible to avoid url change?
the refresh meta tag triggers a GET /app/static/test (as if you would type it in your browser's address field). there is no way to avoid it.

Redirect HTML-page using meta refresh over symbolic link

I have a simple place-holder html-file that I would want to use the header meta tag to redirect automatically. The target is a symolic link (linux) that points to a git-repo directory.
<meta http-equiv="refresh" content="0; url="universitetet/">
However this simply reloads itself. Giving absolute path does so too.
However, using the javascript solution works (and also normal links work fine).
<script language="javascript">
window.location = "universitetet/";
</script>
Get rid of the extra " inside the content attribute.
<meta http-equiv="refresh" content="0; url=universitetet/" />
Side note: Always provide a plain HTML link (Link), in case the user has disabled meta redirection and/or JavaScript.
This code:
<meta content="0; url=(YOUR_LINK)" http-equiv="REFRESH">
Working with me, btw your code have issue with quotations: here content="0; url="universitetet/".