In Java, we can use Apache commons-text, StringEscapeUtils.escapeHtml4(str) to escape HTML characters. pom.xml <dependency> <groupId>org.apache.commons</groupId> <artifactId>commons-text</artifactId> <version>1.8</version> </dependency> JavaEscapeHtmlExample.java package com.mkyong.html; // make sure import the correct commons-text package import org.apache.commons.text.StringEscapeUtils; // @deprecated as of 3.6, use commons-text StringEscapeUtils instead //import org.apache.commons.lang3.StringEscapeUtils; public class JavaEscapeHtmlExample { public static void main(String[] args) { String html = […]

Read more How to escape HTML in Java

For some security reasons, you may need to convert your HTML file into Javascript (js) file, and display the JS file instead of the HTML file directly. The concept is quite simple – using the document.write HTML <h1>Convert HTML to Javascript file</h1> Javascript (js) document.write(‘<h1>Convert HTML to Javascript file</h1>’); 1. Test.html Create a simple HTML […]

Read more How to convert HTML to Javascript (.js) in Java

In this tutorial, we will show you how to extract hyperlink from a HTML page. For example, to get the link from following content : this is text1 <a href=’mkyong.com’ target=’_blank’>hello</a> this is text2… First get the “value” from a tag – Result : a href=’mkyong.com’ target=’_blank’ Later get the “link” from above extracted value […]

Read more How to extract HTML Links with regular expression

HTML tag Regular Expression Pattern <("[^"]*"|'[^’]*’|[^’">])*> Description < #start with opening tag "<" ( # start of group #1 "[^"]*" # allow string with double quotes enclosed – "string" | # ..or ‘[^’]*’ # allow string with single quote enclosed – ‘string’ | # ..or [^’">] # cant contains one single quotes, double quotes and […]

Read more How to validate HTML tag with regular expression

Java2HTML is a tool to converts Java source code into a colorized and browsable HTML page, and the steps are quite straight forward. Steps to convert it 1) Download Java2HTML – http://www.java2html.com/download.html 2) Unzip it , e.g “D:\Java2HTML” 3) Edit the “j2h.bat” file and modify the CLASSPATH variable. Make sure it point to the correct […]

Read more How to convert Java source code to HTML page

As simple, HTML documents are simply a text file made up of many HTML elements. These HTML elements are always between a start tag and end tag. Where the element appears is determined by the order in which the tags appear. HTML Elements An HTML element is everything from the start tag to the end […]

Read more HTML Elements

The getElementsByName() method is use to get the element by name. However be aware of the getElementsByName() method always return an array as output. Caution The method always return an array, and we have to use [] to access the value. For example alert(document.getElementsByName(“myInput”).value); It will prompt out an undefined value alert(document.getElementsByName(“myInput”)[0].value); It will prompt […]

Read more How to get element by name in HTML – getElementsByName

In Java, we can use Apache commons-text to escape the special characters in HTML entities. Special characters as follow: < > ” & pom.xml <dependency> <groupId>org.apache.commons</groupId> <artifactId>commons-text</artifactId> <version>1.8</version> </dependency> EscapeSpecialChar.java package com.mkyong.html; import org.apache.commons.text.StringEscapeUtils; // @deprecated as of 3.6, use commons-text StringEscapeUtils instead //import org.apache.commons.lang3.StringEscapeUtils; public class EscapeSpecialChar { public static void main(String[] args) { […]

Read more How to escape special characters in java?

According to World Wide Web Consortium (W3C), the tag in HTML is deprecated. It is removed in a from its recommendations.W3C encourage to use style sheets (CSS) to define the layout and display properties of HTML elements. However there still a lot of people using it, it still worth to mention a while here. Font […]

Read more Html Font Tutorial