HTMLMeta class

The IBM Toolbox for Java™ HTMLMeta class represents meta-information used within an HTMLHead tag. Attributes in META tags are used when identifying, indexing, and defining information within the HTML document.

Attributes of the META tag include:

  • NAME - the name associated with the contents of the META tag
  • CONTENT - values associated with the NAME attribute
  • HTTP-EQUIV - information gathered by HTTP servers for response message headers
  • LANG - the language
  • URL - used to redirect users from the current page to another URL

For example, to help search engines determine the contents of a page, you might use the following META tag:

     <META name="keywords" lang="en-us" content="games, cards, bridge">

You can also use HTMLMeta to redirect a user from one page to another.

Methods for the HTMLMeta class include:

  • Get and set the NAME attribute
  • Get and set the CONTENT attribute
  • Get and set the HTTP-EQUIV attribute
  • Get and set the LANG attribute
  • Get and set the URL attribute

Example: Creating META tags

The following example creates two META tags:

     // Create a META tag to help search engines determine page content.
     HTMLMeta meta1 = new HTMLMeta();
     meta1.setName("keywords");
     meta1.setLang("en-us");
     meta1.setContent("games, cards, bridge");
     // Create a META tag used by caches to determine when to refresh the page.
     HTMLMeta meta2 = new HTMLMeta("Expires", "Mon, 01 Jun 2000 12:00:00 GMT");
     System.out.print(meta1 + "\r\n" + meta2);

The previous example produces the following tags:

     <meta name="keywords" content="games, cards, bridge">
     <meta http-equiv="Expires" content="Mon, 01 Jun 2000 12:00:00 GMT">