- Apache Common Lang library provides some Util classes for the developer.
- One of the mostly used util class is StringEscapeUtil.
- It has many methods for escaping html,xml,java etc.
- download apache common lang:- download apache common
Project Structure:-
Demo Data:-
package com.sandeep.apache.common.data;
/*
* HtmlDataService.java
* */
public class HtmlDataService {
public static String getHtmlString(){
return "Sandeep Kumar Patel";
}
}
Test Escaping Html:-
<%@ page language="java"
contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"
import="com.sandeep.apache.common.data.HtmlDataService,
org.apache.commons.lang3.StringEscapeUtils"%>
<html>
<head>Test HTML As Text
</head>
<body>
<%=HtmlDataService.getHtmlString() %>
<%=StringEscapeUtils.escapeHtml4(HtmlDataService.getHtmlString()) %>
</body>
</html>
OutPut:-
Download Project:-