[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

JSP set content type problem!!!

Posted on 2007-11-19
6
Medium Priority
?
764 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
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
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 1500 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

Technology Partners: 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

Introduction This article is the second of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers the basic installation and configuration of the test automation tools used by…
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
Viewers learn how to read error messages and identify possible mistakes that could cause hours of frustration. Coding is as much about debugging your code as it is about writing it. Define Error Message: Line Numbers: Type of Error: Break Down…
Viewers will learn about the regular for loop in Java and how to use it. Definition: Break the for loop down into 3 parts: Syntax when using for loops: Example using a for loop:
Suggested Courses

656 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