Solved

JSP set content type problem!!!

Posted on 2007-11-19
6
760 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Get Actionable Data from Your Monitoring Solution

Your communication platform is only as good as the relevance of the information you send. Ensure your alerts get to the right people every time with actionable responses. Create escalation rules that ensure everyone follows the process and nothing is left to chance.

 
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

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…
Java had always been an easily readable and understandable language.  Some relatively recent changes in the language seem to be changing this pretty fast, and anyone that had not seen any Java code for the last 5 years will possibly have issues unde…
Viewers learn about the scanner class in this video and are introduced to receiving user input for their programs. Additionally, objects, conditional statements, and loops are used to help reinforce the concepts. Introduce Scanner class: Importing…
Viewers will learn about arithmetic and Boolean expressions in Java and the logical operators used to create Boolean expressions. We will cover the symbols used for arithmetic expressions and define each logical operator and how to use them in Boole…

717 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