Solved

JSP set content type problem!!!

Posted on 2007-11-19
6
754 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
IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 
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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

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…
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
Video by: Michael
Viewers learn about how to reduce the potential repetitiveness of coding in main by developing methods to perform specific tasks for their program. Additionally, objects are introduced for the purpose of learning how to call methods in Java. Define …
Viewers will learn about the different types of variables in Java and how to declare them. Decide the type of variable desired: Put the keyword corresponding to the type of variable in front of the variable name: Use the equal sign to assign a v…

758 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

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now