• Post Reply Bookmark Topic Watch Topic
  • New Topic

Special characters not appearing on JSP page  RSS feed

 
Shreyash Thakre
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Abhishek Shirodkar wrote:Context:
My application has user interface having JSPs
The database being used in MySQL 5.0.

Problem:
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
 
Abhishek Shirodkar
Greenhorn
Posts: 26
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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...
 
Ulf Dittmer
Rancher
Posts: 42972
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Ulf Dittmer
Rancher
Posts: 42972
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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?
 
Abhishek Shirodkar
Greenhorn
Posts: 26
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
yes its encoded everywhere..
 
Shreyash Thakre
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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","*");
}
 
Abhishek Shirodkar
Greenhorn
Posts: 26
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.*" %>
<html>
<head>
<title>display data from the table using jsp</title>
</head>
<body>
<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;
Class.forName("com.mysql.jdbc.Driver").newInstance();
connection = DriverManager.getConnection(connectionURL, "root", "seg2");
statement = connection.createStatement();
String QueryString = "SELECT * from board";
rs = statement.executeQuery(QueryString);
%>

<%
while (rs.next()) {
%>
<TR>

<TD><%=rs.getString("message")%></TD>


</TR>
<% } %>
<%
// close all the connections.
rs.close();
statement.close();
connection.close();
} catch (Exception ex) {
%>

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

</body>
</html>
 
Milind Mahajan
Ranch Hand
Posts: 77
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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?

-Milind
 
Ulf Dittmer
Rancher
Posts: 42972
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
BhagyaLakshmi Vanguri
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Abhishek Shirodkar
Greenhorn
Posts: 26
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello
Is the character encoded in UTF-8 everywhere?
 
BhagyaLakshmi Vanguri
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 >
<head>
<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?
 
BhagyaLakshmi Vanguri
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Can any one help me in inserting clob data in oracle 10g?
Thanks in advance.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!