0

We have data in DB which contains special characters as &. While displaying the data in view(jsp) page its getting replaced with &.

For eg: DB data: Hari & Kishan in UI displayed as: Hari & Kishan

Currently we have managed use charset='UTF-8' in page import but there is no result of conversion of & to &. below is the code snippet of imports which used in the jsp page.

<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" %>   
    <%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
    <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">

    <html>
    <head>
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <meta name="viewport" content="width=device-width">

Could anyone help in getting this issue solved so that the value showing in view will be similar to Db data.

  • Check if this helps http://stackoverflow.com/questions/12723339/utf-8-encoding-in-jsp-page – Ravi Ranjan Feb 11 '16 at 09:28
  • I checked the link which is provided @RaviRanjan, but my scenario is different here. I am getting the **JSON** data from controller and sending that to fusion-charts as data. i think i need to modify the data while sending to fusion-charts only. Could you please help in this case. – hari kishan Feb 11 '16 at 10:21
  • While sending the data to fusion-charts you can use the commons lang API for this purpose: StringEscapeUtils.unescapeHtml Check this example: http://www.java2s.com/Code/JavaAPI/org.apache.commons.lang/StringEscapeUtilsescapeHtmlStringarg0.htm – Ravi Ranjan Feb 11 '16 at 14:21

1 Answers1

0

you could use JSTL <c:out> tag to do this

<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>

<c:out value="${yourValueFromDB}" /> 

or try to replace all & with &amp;

yourValueFromDB.replaceAll("&(?!amp;)", "&amp;");