Solved

JSP set content type problem!!!

Posted on 2007-11-19
6
759 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
MIM Survival Guide for Service Desk Managers

Major incidents can send mastered service desk processes into disorder. Systems and tools produce the data needed to resolve these incidents, but your challenge is getting that information to the right people fast. Check out the Survival Guide and begin bringing order to chaos.

 
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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

I had a project requirement for a displaying a user workbench .This workbench would consist multiple data grids .In each grid the user will be able to see a large number of data. These data grids should allow the user to 1. Sort 2. Export the …
Java functions are among the best things for programmers to work with as Java sites can be very easy to read and prepare. Java especially simplifies many processes in the coding industry as it helps integrate many forms of technology and different d…
This tutorial explains how to use the VisualVM tool for the Java platform application. This video goes into detail on the Threads, Sampler, and Profiler tabs.
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 …

730 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