Solved

JSP set content type problem!!!

Posted on 2007-11-19
6
758 Views
Last Modified: 2008-02-01
Hello

I have a JSP page which reads hex data from Oracle database. I wrote data in Hex because I don't want to suffer Arabic/Persian language problem in Oracle database.

Then I output data with dehexing them into User's browser in runtime in JSP.

HERE IS MAIN PROBLEM:

I tried to set Content-Type to UTF8 with HTML code like this:
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>

Not WORKED!

I tried to set it to UTF8 with JSP:
<% response.setContentType("text/html; charset=UTF-8");%>

It changes Content Type to UTF8, but not real and good UTF8! Because I cannot see right text.

But when I do not add anything and any changing to charset by any HTML or JSP, and I open page I see strange chars, then I change it to UTF8 manually and it works!!!!! WHY?

Please advice!
0
Comment
Question by:CSecurity
  • 3
  • 2
6 Comments
 
LVL 9

Expert Comment

by:ysnky
ID: 20312240
try this in your jsp page
<%@ page contentType="text/html;charset=UTF-8" %>
0
 
LVL 17

Author Comment

by:CSecurity
ID: 20312360
As I said it sets Browser encoding to UTF8, but data is not shown properly and then I cannot show right text.

But if I remove this, show my data and then user manually set encoding to UTF8, it works.
0
 
LVL 17

Author Comment

by:CSecurity
ID: 20312369
I think some problem exists in Java String. Maybe! Or out.println

I don't know! But it not works in anyway I tried...
0
How Do You Stack Up Against Your Peers?

With today’s modern enterprise so dependent on digital infrastructures, the impact of major incidents has increased dramatically. Grab the report now to gain insight into how your organization ranks against your peers and learn best-in-class strategies to resolve incidents.

 
LVL 1

Expert Comment

by:r_ran
ID: 20328212
CSecurity, ysnky gave you the right solution. You tried <% response.setContentType("text/html; charset=UTF-8");%>, it is NOT the same as what ynsky suggested:
<%@ page contentType="text/html;charset=UTF-8" %>
Try the @ page and see that it works. Look at this page: http://wiki.apache.org/tomcat/Tomcat/UTF-8 for more tomcat UTf-8 tips.
0
 
LVL 17

Author Comment

by:CSecurity
ID: 20342637
Thanks but:

1) I'm not using Tomcat. I'm using SJSWS

2) I tried that, that code sets my content type to UTF8 but as I said in my question, then my text is not shown properly. And after that even by setting encoding to something else then again setting it to UTF8, again not works.

0
 
LVL 1

Accepted Solution

by:
r_ran earned 500 total points
ID: 20345662
The solution I described works in Tomcat - setting using <% response.setCotentType... %> gives a UTF-8 page that doesn't encode correctly as you described, and replacing it with <% @ page conetntType= %> solves the problem. I didn't try farsi but it worked for other semitic (right-to-left) langugages.

I didn't try this on SJSWS - you should get support from Sun if you use their commercial products :)

Maybe this will help - add -Dfile.encoding=UTF-8 to your JAVA_OPTS or any java arguments that are used to start SJSWS - perhaps it uses this variable to encode it's output.
0

Featured Post

Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
table example 4 32
jboss wildfly 10.1 10 230
ejb wildfly example 2 23
Need help aligning JRadioButton that put in a box using GridBagLayout 2 18
For beginner Java programmers or at least those new to the Eclipse IDE, the following tutorial will show some (four) ways in which you can import your Java projects to your Eclipse workbench. Introduction While learning Java can be done with…
In this post we will learn how to connect and configure Android Device (Smartphone etc.) with Android Studio. After that we will run a simple Hello World Program.
Viewers will learn about if statements in Java and their use The if statement: The condition required to create an if statement: Variations of if statements: An example using if statements:
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …

860 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question