Forums Register Login
Special characters not appearing on JSP page

Abhishek Shirodkar wrote:Context:
My application has user interface having JSPs
The database being used in MySQL 5.0.

The problem I am facing is some information in database is stored as special character.
Special character is not displayed correctly on the JSP page.
The datatype is BLOB.
The special character is displayed correctly in the database table but not diaplaying on the Jsp page when it is running..
I specified pageEncoding or content type in JSP pages. and also i changed the character set to UTF-8 but still does not works.
Any help is greatly appreciated.

Thanks in advnce...

I think if you want special characters to be displayed in JSP page correctly, you need to use escape characters. http://www.javapractices.com/topic/TopicAction.do?Id=96
can you please tell me how to use escape characters in jsp page...can you please send me the sample code of the escape characters to be used in jsp.

thanks in advance...
Moderator's note: I deleted Abhishek's post (since it was a duplicate) just as Shreyash was answering it. Luckily -although generally unnecessary- Shreyash included the full original post in the reply.
Is the character encoded in UTF-8 everywhere? Meaning, by the browser when it is sent to the server, in the app server, in the DB, on the way back from the DB to the app server, and then on to the web browser?
yes its encoded everywhere..
suppose say if you are getting data which contains special characters, and not displaying that on jsp page.
so you can use the replaceAll method to display the special characters in proper format.

I faced the same problem, but using this it was solved.

String strData = "";
if(Obj.getBlobData() != null)
strData = Obj.getBlobData();
strData = strData.replaceAll("%0D%0A","\n");
strData = strData.replaceAll("%20"," ");
strData = strData.replaceAll("%3E",">");
strData = strData.replaceAll("%3C","<");
strData = strData.replaceAll("%23","#");
strData = strData.replaceAll("%25","%");
strData = strData.replaceAll("%7B","{");
strData = strData.replaceAll("%7D","}");
strData = strData.replaceAll("%7C","|");
strData = strData.replaceAll("%5C","\\\\");
strData = strData.replaceAll("%21","!");
strData = strData.replaceAll("%22","\"");
strData = strData.replaceAll("%27","'");
strData = strData.replaceAll("%2C",",");
strData = strData.replaceAll("%2E",".");
strData = strData.replaceAll("%2A","*");
the following is my jsp code..can you please tell me where the code which you have been posted will be fit...

<%@ page import="java.sql.*" %>
<%@ page import="java.io.*" %>
<title>display data from the table using jsp</title>
<h2>Data from the table 'board' of database 'employee'</h2>

try {
String connectionURL = "jdbc:mysql://localhost:3306/employee";
Connection connection = null;
Statement statement = null;
ResultSet rs = null;
connection = DriverManager.getConnection(connectionURL, "root", "seg2");
statement = connection.createStatement();
String QueryString = "SELECT * from board";
rs = statement.executeQuery(QueryString);

while (rs.next()) {


<% } %>
// close all the connections.
} catch (Exception ex) {

out.println("Unable to connect to database.");
<TD><form ACTION="welcome_to_database_query.jsp" method="get"></form>
<button type="submit"><-- back</button></TD>

Any chance you are reading the BLOB as array of bytes from the database and making a String out of it before passing it on to the web layer for display?


Abhishek Shirodkar wrote:the following is my jsp code..

I don't see where you are specifying UTF-8 as the encoding.

I'll merely mention that it's considered quite bad design to have DB access code in a JSP.
Hello abishek,

I am also facing problem while dealing with speical characters.
My jsp page contains a html editor and message entered into that editor must be stored in the data base. But while carrying the content entered in the editor to the action class some character like(",_) are not getting recognised and are changed into question marks "?".

I am trying to store this editor content into a clob in oracle.

please suggest me the solutions.
Is the character encoded in UTF-8 everywhere?
Yes i am trying to set the charset as UT-8 in my jsp page.
My jsp page is as below:

<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" %>

<html >
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<link href="/mcp/styles/sop.css" rel="stylesheet" type="text/css" />
<title>MCP ESSAY</title>

But when i try to check for character encoding (using the method request.getCharacterEncoding() )before retrieving any values through request.getParameter() method in the action class it is displaying null value as output.

How to set the character encoding in a jsp page........Any suggestion regarding this?
Can any one help me in inserting clob data in oracle 10g?
Thanks in advance.

This thread has been viewed 8309 times.

All times above are in ranch (not your local) time.
The current ranch time is
Dec 15, 2018 21:07:07.