Search code examples
htmltomcatintellij-ideaencodingutf-8

tomcat server language encoding problem (UTF-8)


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

Solution

  • 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.