Announcement Announcement Module
Collapse
No announcement yet.
messageSource only support ISO-8859-1 ?! Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • messageSource only support ISO-8859-1 ?!

    Hi,
    I use jsp tag in my form like this,

    Code:
    <?xml version="1.0" encoding="UTF-8" ?>
    <%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    
    <%@ taglib prefix="form"   uri="http://www.springframework.org/tags/form" %>
    <%@ taglib prefix="spring" uri="http://www.springframework.org/tags" %>
    <%@ taglib prefix="c"      uri="http://java.sun.com/jsp/jstl/core" %>
    <%@ taglib prefix="fmt"    uri="http://java.sun.com/jsp/jstl/fmt" %>
    
    <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
    
    <head>
    	<title><spring:message code="form.title" /></title>
    	<meta http-equiv="content-type" content="text/html; charset=utf-8" />
    	<link href="<c:url value="/css/style.css"/>" rel="stylesheet" type="text/css" />
    </head>
    The configuration file and message file are here:

    i18n.properties
    Code:
      form.title=注册新用户
    mynode-servlet.xml

    Code:
    	<bean id="messageSource" class="org.springframework.context.support.ResourceBundleMessageSource">
    		<property name="basename" value="i18n"/>
    	</bean>
    When I use browser to test the page,
    http://localhost:8080/mynode/hello.htm

    it displays

    Code:
    <title>注册新用户</title>
    I edit and create all files by UTF-8.

    I guess org.springframework.context.support.ResourceBundle MessageSource only works on ISO-8859-1.

    Any solution about that?

  • #2
    You have to use native2ascii to encode chinese chars to asc.
    This tools includes in jdk.
    It's not a spring problem.

    Comment


    • #3
      nativ2ascii i18.properties msg.txt

      Thanks,
      I've tried to fix it.
      1) cd c:\work\mynode\war\WEB-INF\classes
      2) native2ascii i18n.properties msg.txt
      3) copy msg.txt i18n.properties

      I check the i18n.properties encodeing by notepad, it displays ANSI encode. the content displays.

      Code:
      form.title=\u5a09\u3125\u553d\u93c2\u626e\u6564\u93b4\ufffd
      I tried to save as both UTF-8 and ANSI.

      The result page dosen't work either.

      Code:
      <title>娉ㄥ唽鏂扮敤鎴�</title>
      The relative files are listed here:
      mynode-servlet.xml

      Code:
      	<bean id="messageSource" class="org.springframework.context.support.ResourceBundleMessageSource">
      		<property name="basename" value="i18n"/>
      	</bean>
      i18n.properties
      Code:
      form.title=\u5a09\u3125\u553d\u93c2\u626e\u6564\u93b4\ufffd
      register.jsp
      Code:
      <?xml version="1.0" encoding="UTF-8" ?>
      <%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
      <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
      
      <%@ taglib prefix="form"   uri="http://www.springframework.org/tags/form" %>
      <%@ taglib prefix="spring" uri="http://www.springframework.org/tags" %>
      <%@ taglib prefix="c"      uri="http://java.sun.com/jsp/jstl/core" %>
      <%@ taglib prefix="fmt"    uri="http://java.sun.com/jsp/jstl/fmt" %>
      
      <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
      
      <head>
      	<title><spring:message code="form.title" /></title>
      	<meta http-equiv="content-type" content="text/html; charset=utf-8" />
      	<link href="<c:url value="/css/style.css"/>" rel="stylesheet" type="text/css" />
      </head>
      
      <body>
      <div id="content">
      </div>
      
      </body>
      </html>

      web.xml

      
      Code:
      <?xml version="1.0" encoding="UTF-8"?>
      
      <web-app version="2.4" xmlns="http://java.sun.com/xml/ns/j2ee"
      	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
      	xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee 
               http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">
      
      	<listener>
      		<listener-class>
      			org.springframework.web.context.ContextLoaderListener
      		</listener-class>
      	</listener>
      
      	<servlet>
      		<servlet-name>mynode</servlet-name>
      		<servlet-class>
      			org.springframework.web.servlet.DispatcherServlet
      		</servlet-class>
      		<load-on-startup>1</load-on-startup>
      	</servlet>
      
      	<servlet-mapping>
      		<servlet-name>mynode</servlet-name>
      		<url-pattern>*.htm</url-pattern>
      	</servlet-mapping>
      
      	<welcome-file-list>
      		<welcome-file>index.jsp</welcome-file>
      	</welcome-file-list>
      
      	<jsp-config>
      		<taglib>
      			<taglib-uri>/core</taglib-uri>
      			<taglib-location>/WEB-INF/tld/c.tld</taglib-location>
      		</taglib>
      		<taglib>
      			<taglib-uri>/fmt</taglib-uri>
      			<taglib-location>/WEB-INF/tld/fmt.tld</taglib-location>
      		</taglib>
      		<taglib>
      			<taglib-uri>/spring</taglib-uri>
      			<taglib-location>/WEB-INF/tld/spring.tld</taglib-location>
      		</taglib>
      		<taglib>
      			<taglib-uri>/form</taglib-uri>
      			<taglib-location>
      				/WEB-INF/tld/spring-form.tld
      			</taglib-location>
      		</taglib>
      	</jsp-config>
      
      </web-app>

      Comment


      • #4
        native2ascii -encoding gbk i18n.properties newi18n.properties

        Comment


        • #5
          native2ascii -encoding utf-8 works for i18n

          thanks very much, duoclb.

          I use utf-8 and gbk to test the result. they both works.

          Code:
          native2ascii -encoding utf-8 i18n.properties msg.txt
          or

          Code:
          native2ascii -encoding gbk i18n.properties msg.txt

          Comment

          Working...
          X