0

I'm using Intellij Ultimate. When I run the html file in browser it works well with encoding. But, when I run as localhost url (tomcat server) the characters cracks.image of encoding cracked this is my if.html file

<!DOCTYPE html>
<html lang="en">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<head>
    <meta charset="utf-8">
    <title>title</title>
</head>
<h1>If-else Example</h1>
<form method="post" action="if.jsp">
    <body>
    이름 : <label>
        <input name="name">
    </label>
    <p></p>
    좋아하는 색깔 : <label>
        <select name="color">
            <option value="blue" selected>파랑</option>
            <option value="red">빨강</option>
            <option value="orange">오렌지</option>
            <option value="etc">기타</option>
        </select>
    </label>
    <p></p>
    <input type="submit" value="보내기">
    </body>
</form>
</html>

right feature of file

I mapped this if.html file through web.xml.

    <servlet>
        <servlet-name>if</servlet-name>
        <jsp-file>/if.html</jsp-file>
        <init-param>
            <param-name>encoding</param-name>
            <param-value>UTF-8</param-value>
        </init-param>
    </servlet>
    <servlet-mapping>
        <servlet-name>if</servlet-name>
        <url-pattern>*.html</url-pattern>
    </servlet-mapping>

Other Jsp files or mapped java files encode well in UTF-8 but, only html files cracked. I want to encode html file as UTF-8 properly. Thank you for your help in advance.

I tried following this way but doesn't work.

  1. set Intellij project encoding, global encoding, Default encoding for properties files to UTF-8
  2. added java option in Tomcat Configuration -Dfile.encoding=UTF-8
  3. added Intellij custom VM option -Dfile.encoding=UTF-8
  4. added URLEncoding="UTF-8" in server.xml at tomcat container
skomisa
  • 16,436
  • 7
  • 61
  • 102
beingicy
  • 5
  • 5
  • What language is that btw? – g00se Mar 04 '23 at 13:42
  • @g00se It's Java Maven project. – beingicy Mar 04 '23 at 13:51
  • @g00se Oh, sorry it's Korean. I have a problem with encoding korean through utf-8. – beingicy Mar 04 '23 at 13:54
  • You face a [mojibake](https://en.wikipedia.org/wiki/Mojibake) case (*example in Python for its universal intelligibility*): ```'보내기'.encode('utf-8').decode('cp1252')``` returns ```보내기```. Covers the line ``) … – JosefZ Mar 04 '23 at 14:47
  • Ah OK. It might also help to include the actual characters you're using, probably preferably in Unicode escaped format \uABCD – g00se Mar 04 '23 at 15:02
  • 1
    Your file as shown opens correctly in Chrome **if saved in UTF-8 encoding**. Despite your settings, the file itself is not encoded in UTF-8. – Mark Tolonen Mar 04 '23 at 18:45
  • Second time today I've posted this on SO: https://cwiki.apache.org/confluence/display/TOMCAT/Character+Encoding – Christopher Schultz Mar 30 '23 at 17:53

1 Answers1

0

since you are having problem with UTF-8, you can try the UTF-8 + BOM encoding as it always works for me in any case as my tomcat server used to show a huge error on typing arabic. So now you should be able to run them on both servers. This should do the trick.

  • [There's absolutely no need to include a BOM in an HTML file.](https://stackoverflow.com/a/17425321/3439404). On the contrary, [the byte-order mark has been known to cause problems.](https://www.w3.org/International/questions/qa-byte-order-mark#problems) – JosefZ Mar 04 '23 at 15:33
  • @JosefZ Hi, But I think that whenever I experience such issues, I always use UTF8+BOM as it usually solves my problems instead of ANSI or Unicode. That's why I said. – meedhansh gupta Mar 04 '23 at 16:14
  • Your answer would be fine if posted as a suggestion in a comment to the question, but just because including BOM solves your problems it does not follow that it will solve the OP's problems. In fact it may cause problems. In support of the comment from @JosefZ: from the [JetBrains documentation](https://www.jetbrains.com/help/idea/settings-file-encodings.html): _"By default, IntelliJ IDEA creates UTF-8 files without the BOM because some software is not compatible with the BOM, and it may be a problem when interpreting scripts."_ – skomisa Mar 04 '23 at 19:50
  • Thank you everyone. I just make new project and it works. I think there were some problem of form in my project. First time I created a new project, I made with javax. But, since I was using tomcat 11 I changed some settings to jakarta. I wonder in there, there's a problem. btw, I will try the way unicode and byte order mark if there's other encoding issues. Thank you so much for your help. – beingicy Mar 05 '23 at 03:33
  • You are welcome beingicy! – meedhansh gupta Mar 12 '23 at 13:32