wood burning stoves 2.0*
The moose likes HTML, CSS and JavaScript and the fly likes Cant insert euro symbol Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Engineering » HTML, CSS and JavaScript
Bookmark "Cant insert euro symbol" Watch "Cant insert euro symbol" New topic
Author

Cant insert euro symbol

miguel lisboa
Ranch Hand

Joined: Feb 08, 2004
Posts: 1281
i'm not sure if this is an html issue, but here it goes:
my webpage:

i'm using mysql5 database with latin1 and latin_swedish and when i try to input altgr + e (euro symbol) i get a question mark in database (and when retrieving data from database the question mark appears on the webpage)
also, i tried manually inserting the euro symbol in database: in this case the symbol displays correctly on the webpage
if instead i try to use the pound symbol (altgr + 3) all goes fine

what might be the problem?

thanks in advance


java amateur
Hauke Ingmar Schmidt
Rancher

Joined: Nov 18, 2008
Posts: 433
    
    2
Latin1 does not include the euro sign. ISO-8859-15/Latin9 does.
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61095
    
  66

Any reason not to be using UTF-8?


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
miguel lisboa
Ranch Hand

Joined: Feb 08, 2004
Posts: 1281
Hauke Ingmar Schmidt wrote:Latin1 does not include the euro sign. ISO-8859-15/Latin9 does.

i carefully searched for column charset in mysql tables, but no latin9..
can you explain a bit further how i should proceed?
miguel lisboa
Ranch Hand

Joined: Feb 08, 2004
Posts: 1281
Bear Bibeault wrote:Any reason not to be using UTF-8?

no
i just changed from latin1 to utf8 in mysql table charset but the problem is still there..
Hauke Ingmar Schmidt
Rancher

Joined: Nov 18, 2008
Posts: 433
    
    2
If you are free to choose: Use UTF-8, like Bear recommend, no question there.

Otherwise you could look up the alternative names that MySQL may use. I just fired up the MySQL query browser and am shocked by the incosistent and chaotic list there...
Hauke Ingmar Schmidt
Rancher

Joined: Nov 18, 2008
Posts: 433
    
    2
miguel lisboa wrote:
i just changed from latin1 to utf8 in mysql table charset but the problem is still there..


The problem is ... where exactly? You have to ensure that every part of the application, from data input to database connection to output uses the correct and specified encoding.
miguel lisboa
Ranch Hand

Joined: Feb 08, 2004
Posts: 1281
Hauke Ingmar Schmidt wrote:If you are free to choose: Use UTF-8, like Bear recommend, no question there.

Otherwise you could look up the alternative names that MySQL may use. I just fired up the MySQL query browser and am shocked by the incosistent and chaotic list there...

so so far i can conclude this is not an html issue, but instead a database problem?
Hauke Ingmar Schmidt
Rancher

Joined: Nov 18, 2008
Posts: 433
    
    2
miguel lisboa wrote:
so so far i can conclude this is not an html issue, but instead a database problem?


Sorry, no. Encoding problems can occur in every step of the application. But if the database can't hold the symbol there is no need to work at the higher layers. The problem can begin with entering the data into the db. Let's say you use the console program... then the encoding of the console can mangle with the characters.

If you still use the very same HTML fragment that you showed above then there is an encoding used that can't display the euro symbol.
miguel lisboa
Ranch Hand

Joined: Feb 08, 2004
Posts: 1281
Hauke Ingmar Schmidt wrote:
miguel lisboa wrote:
i just changed from latin1 to utf8 in mysql table charset but the problem is still there..


The problem is ... where exactly? You have to ensure that every part of the application, from data input to database connection to output uses the correct and specified encoding.


where? in mysql5 table charset, using mysql query browser
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18541
    
    8

miguel lisboa wrote:i just changed from latin1 to utf8 in mysql table charset but the problem is still there..


Well, yeah. You corrupted the data when you wrote it as latin1. Just telling MySQL that it should now treat the corrupt data as UTF-8 will not un-corrupt the data.

But Hauke Ingmar is correct. Let me point you to this article Character Conversions from Browser to Database which explains that concept in detail.
miguel lisboa
Ranch Hand

Joined: Feb 08, 2004
Posts: 1281
Hauke Ingmar Schmidt wrote:
miguel lisboa wrote:
so so far i can conclude this is not an html issue, but instead a database problem?


Sorry, no. Encoding problems can occur in every step of the application. But if the database can't hold the symbol there is no need to work at the higher layers. The problem can begin with entering the data into the db. Let's say you use the console program... then the encoding of the console can mangle with the characters.

If you still use the very same HTML fragment that you showed above then there is an encoding used that can't display the euro symbol.

what you are telling me is to change (inside my html) from charset = iso-8859-1 to charset = iso-8859-15?
miguel lisboa
Ranch Hand

Joined: Feb 08, 2004
Posts: 1281
Paul Clapham wrote:
miguel lisboa wrote:i just changed from latin1 to utf8 in mysql table charset but the problem is still there..


Well, yeah. You corrupted the data when you wrote it as latin1. Just telling MySQL that it should now treat the corrupt data as UTF-8 will not un-corrupt the data.

But Hauke Ingmar is correct. Let me point you to this article Character Conversions from Browser to Database which explains that concept in detail.

this is a home aplication, so i can access everything: first i changed mysql charset to utf8 and only after that i made another submission to datavbase, but the problem persisted

as to your link asap i'll give it a look, thank you
Hauke Ingmar Schmidt
Rancher

Joined: Nov 18, 2008
Posts: 433
    
    2
miguel lisboa wrote:
what you are telling me is to change (inside my html) from charset = iso-8859-1 to charset = iso-8859-15?


If you decided to go for UTF-8 then setting it to ISO-8859-15 is not a good idea.
miguel lisboa
Ranch Hand

Joined: Feb 08, 2004
Posts: 1281
Hauke Ingmar Schmidt wrote:
miguel lisboa wrote:
what you are telling me is to change (inside my html) from charset = iso-8859-1 to charset = iso-8859-15?


If you decided to go for UTF-8 then setting it to ISO-8859-15 is not a good idea.

so what you recomend for both mysql and html?
Hauke Ingmar Schmidt
Rancher

Joined: Nov 18, 2008
Posts: 433
    
    2
UTF-8 everywhere. Please have a look at the article that Paul linked. You need to ensure that your business layer (PHP?) uses the same encoding, especially in the database connection (string).
miguel lisboa
Ranch Hand

Joined: Feb 08, 2004
Posts: 1281
Hauke Ingmar Schmidt wrote:UTF-8 everywhere. Please have a look at the article that Paul linked. You need to ensure that your business layer (PHP?) uses the same encoding, especially in the database connection (string).

i'm using java (servlets and jsp)

thank you
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18541
    
    8

I used UTF-8 for my personal application which uses MySQL. It isn't a web application but I might make it into one in the near future.

You've already had one character which didn't exist in the charset you originally chose. Switching to ISO-8859-15 takes care of that one character. What do you do when that happens again? But if you choose UTF-8 then that problem goes away. So just use UTF-8.
miguel lisboa
Ranch Hand

Joined: Feb 08, 2004
Posts: 1281
Paul Clapham wrote:I used UTF-8 for my personal application which uses MySQL. It isn't a web application but I might make it into one in the near future.

You've already had one character which didn't exist in the charset you originally chose. Switching to ISO-8859-15 takes care of that one character. What do you do when that happens again? But if you choose UTF-8 then that problem goes away. So just use UTF-8.

pardon my total ignorance and confusion about all this: are you suggesting using UTF-8 with
1) mysql
2) within html
3) in both?

thank you :)
Hauke Ingmar Schmidt
Rancher

Joined: Nov 18, 2008
Posts: 433
    
    2
miguel lisboa wrote:pardon my total ignorance and confusion about all this: are you suggesting using UTF-8 with
1) mysql
2) within html
3) in both?


The HTML just displays the characters as they are. The meta tag just gives a hint about how to interpret the bytes that represent the characters. If you choose the wrong one, then the characters will be displayed wrongly. So you don't really have a choice here. You have to tell the encoding as is. (Encodings can't be guessed.)

But still you must check that your JSPs (or servlets, in case of raw output) and possibly your server don't send any other meta information or do some encoding conversion. Oh, and did I mention the db connection? ;-)
miguel lisboa
Ranch Hand

Joined: Feb 08, 2004
Posts: 1281
i'm not sure where to add this bit of code (which is taken from Paul's link)
Add the following code just before reading any parameters in the previous JSP file.

String paramEncoding = application.getInitParameter("PARAMETER_ENCODING");
request.setCharacterEncoding(paramEncoding);


i have a jsp and a servlet...
Shankar Tanikella
Ranch Hand

Joined: Jan 30, 2011
Posts: 329

To test the current scenario put it in your JSP and for the actual purpose write a filter and set it there so that it serves for all you JSP's (if you have more) in application


Have Fun with Java
little,little.. little by little makes a lot..
miguel lisboa
Ranch Hand

Joined: Feb 08, 2004
Posts: 1281
i did it all but i get a null
mysql table has charset: utf8
my jsp has it:
<%@page pageEncoding="UTF-8" contentType="text/html; charset=UTF-8" %>
<%
if (session.getAttribute("xxx") == null) {
response.sendRedirect(redirectURL);
return;
}
String paramEncoding = application.getInitParameter("PARAMETER_ENCODING");
request.setCharacterEncoding(paramEncoding);
if (session.getAttribute("xxx").equals("xxx")) {
%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd">

<html dir = "ltr" lang = "pt">

<head>
<title>avulsas: escrever</title>
<!--<meta http-equiv = "Content-Type" content="text/html; charset=iso-8859-1">-->
<meta http-equiv = "Content-Type" content="text/html; charset=UTF-8">

my servlet has the added code:

my web.xml has it:
<!DOCTYPE web-app PUBLIC
'-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN'
'http://java.sun.com/dtd/web-app_2_3.dtd'>
<web-app>
...
<context-param>
<param-name>PARAMETER_ENCODING</param-name>
<param-value>UTF-8</param-value>
</context-param>
</web-app>


my server.xml has it:

<?xml version="1.0" encoding="UTF-8"?>
<Service name="Catalina">
<!-- Define a non-SSL HTTP/1.1 Connector on port 8080 -->
<Connector port="80" maxHttpHeaderSize="8192"
maxThreads="150" minSpareThreads="25" maxSpareThreads="75"
enableLookups="false" redirectPort="8443" acceptCount="100"

URIEncoding="UTF-8"
...


after all this i get a null when inserting the euro symbol...
what may i be doing wrong?

thanks in advance>
miguel lisboa
Ranch Hand

Joined: Feb 08, 2004
Posts: 1281
i just noticed this error message (along with the null i referred):
6/Fev/2011 19:01:37 org.apache.tomcat.util.http.Parameters processParameters
WARNING: Parameters: Character decoding failed. Parameter skipped.
java.io.CharConversionException: isHexDigit
at org.apache.tomcat.util.buf.UDecoder.convert(UDecoder.java:87)
at org.apache.tomcat.util.buf.UDecoder.convert(UDecoder.java:48)
at org.apache.tomcat.util.http.Parameters.urlDecode(Parameters.java:411)
at org.apache.tomcat.util.http.Parameters.processParameters(Parameters.java:393)
at org.apache.tomcat.util.http.Parameters.processParameters(Parameters.java:344)
at org.apache.catalina.connector.Request.parseParameters(Request.java:2449)
at org.apache.catalina.connector.Request.getParameter(Request.java:1010)
at org.apache.catalina.connector.RequestFacade.getParameter(RequestFacade.java:353)
at blog.Escrever.doGet(Escrever.java:43) // empty line in my code
at blog.Escrever.doPost(Escrever.java:61) // empty line in my code
at javax.servlet.http.HttpServlet.service(HttpServlet.java:647)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:729)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:269)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:188)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:213)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:172)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:117)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:108)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:174)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:879)
at org.apache.coyote.http11.Http11BaseProtocol$Http11ConnectionHandler.processConnection(Http11BaseProtocol.java:665)
at org.apache.tomcat.util.net.PoolTcpEndpoint.processSocket(PoolTcpEndpoint.java:528)
at org.apache.tomcat.util.net.LeaderFollowerWorkerThread.runIt(LeaderFollowerWorkerThread.java:81)
at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:689)
at java.lang.Thread.run(Unknown Source)


Hauke Ingmar Schmidt
Rancher

Joined: Nov 18, 2008
Posts: 433
    
    2
The code you showed is needed when dynamically setting the encoding. Do you set the application init parameter to the correct value?

Just try to get it working without being dynamic first.
miguel lisboa
Ranch Hand

Joined: Feb 08, 2004
Posts: 1281
in first place i wanna thank all of you trying to help me sorting this out: thanks!

now the bad news: as i guess i said before all of this is quite new and confusing to me... :cry:

so, where should i look for an answer to:
Do you set the application init parameter to the correct value?
:confused:
Hauke Ingmar Schmidt
Rancher

Joined: Nov 18, 2008
Posts: 433
    
    2
You have following in you JSP source:


I don't think the encoding problem should be your main interest now. I recommend working through some fundamental books or tutorials regarding this technologies.
miguel lisboa
Ranch Hand

Joined: Feb 08, 2004
Posts: 1281
Hauke Ingmar Schmidt wrote:You have following in you JSP source:


I don't think the encoding problem should be your main interest now. I recommend working through some fundamental books or tutorials regarding this technologies.

i simply followed article's procedure...

could you please answer my previous question?
Hauke Ingmar Schmidt
Rancher

Joined: Nov 18, 2008
Posts: 433
    
    2
You don't need this parameter because you don't need the dynamic behaviour. The article is about the general pitfalls and not about fixing your problem. But it is still explicitely stated in the article where to set this value.
 
 
subject: Cant insert euro symbol