在JSP的UTF8 charset使用在本地化的俄国标志。 Spring MVC

时间:2016-01-14 00:21:49

标签: java jsp spring-mvc utf-8 localization

我使用英语和俄语在我的网络应用程序中进行了本地化。 但是,当我切换到俄语时,它显示我“??????”而不是正确的话。有什么问题?但是,当我把我的JSP俄语单词,而没有<spring:message code="label.login" />时,它表现得很好。帮帮我! 这是我的 messages_en.properties 文件

label.login=Login
label.password=Password

这是我的 messages_ru.properties 文件

label.login=Логин
label.password=Пароль

这是我的login.jsp

<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
	<?xml version="1.0" encoding="UTF-8"?>
<%@taglib uri="http://www.springframework.org/tags/form" prefix="form"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@taglib uri="http://www.springframework.org/tags" prefix="spring"%>
<%
	request.setCharacterEncoding("UTF-8");
	response.setCharacterEncoding("UTF-8");
%>
<!DOCTYPE html>
<html>
<head>
<title>Войти в систему | Violence and Hate</title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/> 
<link href="<c:url value="/resources/bootstrap/bootstrap.css"/>"
	rel="stylesheet" type="text/css">

<link href="<c:url value="/resources/CSS/styles.css"/>" rel="stylesheet"
	type="text/css">
<script src="<c:url value="/resources/Angular/angular.min.js"/>"></script>

</head>

<body>

	<img class="img-responsive center-block"
		src="<c:url value="/resources/logo/logo.png"/>" />

<br>
	<div class="centerBlock text-center loginForm">
		<form:form method="post" action="j_spring_security_check"
			modelAttribute="users" ng-app="myApp" ng-controller="validateCtrl"
			name="myForm" novalidation="true">

			<div class="form-group">
			 <div class="alert alert-error">${message}</div>
				<label class="control-label" for="username"><spring:message
                                code="label.login" /></label>
				<form:input class="form-control input-sm" path="username" id="username" type="text"
					name="username" ng-model="username" required="true" />
				<div style="color: black"
					ng-show="myForm.username.$dirty && myForm.username.$invalid">
					<span ng-show="myForm.username.$error.required"><label><spring:message
                                code="label.enterlogin" /></label></span>
				</div>
			</div>
			<div class="form-group">
				<label class="control-label" for="password"><spring:message code="label.password" /></label>
				<form:input class="form-control input-sm" path="password" type="password" name="password"
					ng-model="password" id="password" required="true" />

				<div style="color: black"
					ng-show="myForm.password.$dirty && myForm.password.$invalid">
					<span ng-show="myForm.password.$error.required"><label><spring:message
                                code="label.enterpassword"/></label></span>
				</div>

			</div>

<div class="textCenter">
			<button type="submit" class="btn btn-success btn-sm btn-block"
				ng-disabled="myForm.username.$dirty && myForm.username.$invalid ||
  myForm.password.$dirty && myForm.password.$invalid"><spring:message
                                code="label.loginbutton" /></button></div>

		</form:form>
</div>
	<br>
<div class="text-center">
	<a href="registration"><button class="btn btn-primary"><spring:message
                                code="label.regbutton" /></button></a>
	<a href="restorepass"><button class="btn btn-primary"><spring:message
                                code="label.restorepassbutton" /></button></a>
</div>

	<script>
		var app = angular.module('myApp', []);
		app.controller('validateCtrl', function($scope) {
			$scope.username = '';
			$scope.password = '';
		});
	</script>
</body>
<script src="<c:url value="/resources/Jquery/jquery-2.1.4.min.js"/>"
	type="text/javascript"></script>
<script src="<c:url value="/resources/bootstrap/bootstrap.js"/>"
	type="text/javascript"></script>
</html>

这是我的 mvc-dispatcher-servlet.xml

    <?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:context="http://www.springframework.org/schema/context"
    xmlns:aop="http://www.springframework.org/schema/aop" xmlns:mvc="http://www.springframework.org/schema/mvc"
    xsi:schemaLocation="http://www.springframework.org/schema/beans 
    http://www.springframework.org/schema/beans/spring-beans-4.0.xsd 
    http://www.springframework.org/schema/aop
    http://www.springframework.org/schema/aop/spring-aop-4.0.xsd
    http://www.springframework.org/schema/mvc
    http://www.springframework.org/schema/mvc/spring-mvc-4.0.xsd
    http://www.springframework.org/schema/tx
    http://www.springframework.org/schema/tx/spring-tx-4.0.xsd
    http://www.springframework.org/schema/context
    http://www.springframework.org/schema/context/spring-context.xsd 
    http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/context  http://www.springframework.org/schema/context/spring-context-3.0.xsd http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx.xsd
     "
    xmlns:tx="http://www.springframework.org/schema/tx">


    <context:component-scan base-package="
    com.vandh.app " />


    <context:property-placeholder location="classpath:database.properties" />
    <mvc:resources mapping="/resources/**" location="/resources/" />
    <mvc:resources mapping="/avatars/**" location="file:/resources/avatars"/>
    <mvc:annotation-driven />
    <bean id="dataSource"
        class="org.springframework.jdbc.datasource.DriverManagerDataSource">
        <property name="driverClassName" value="${database.driver}" />
        <property name="url" value="${database.url}" />
        <property name="username" value="${database.user}" />
        <property name="password" value="${database.password}" />

    </bean>
    <bean id="sessionFactory"
        class="org.springframework.orm.hibernate4.LocalSessionFactoryBean">
        <property name="dataSource" ref="dataSource" />
        <property name="configLocation" value="classpath:hibernate.cfg.xml" />
    </bean>

        <bean id="multipartResolver"
   class="org.springframework.web.multipart.commons.CommonsMultipartResolver">
    <property name="maxUploadSize" value="5000000"/>
</bean>
<bean id="messageSource"
        class="org.springframework.context.support.ReloadableResourceBundleMessageSource">
        <property name="basename" value="classpath:messages" />
        <property name="defaultEncoding" value="UTF-8" />
         <property name="fallbackToSystemLocale" value="false" />
    </bean>

    <bean id="localeResolver"
        class="org.springframework.web.servlet.i18n.CookieLocaleResolver">
        <property name="defaultLocale" value="ru" />
        <property name="cookieName" value="myAppLocaleCookie"></property>
        <property name="cookieMaxAge" value="3600"></property>
    </bean>

    <mvc:interceptors>
        <bean
            class="org.springframework.web.servlet.i18n.LocaleChangeInterceptor">
            <property name="paramName" value="locale" />
        </bean>
    </mvc:interceptors>

    <tx:annotation-driven/>     
    <bean id="transactionManager"
        class="org.springframework.orm.hibernate4.HibernateTransactionManager">
        <property name="sessionFactory" ref="sessionFactory" />
    </bean>

    <bean id="persistenceExceptionTranslationPostProcessor"
        class="org.springframework.dao.annotation.PersistenceExceptionTranslationPostProcessor" />

    <bean
        class="org.springframework.web.servlet.view.InternalResourceViewResolver">



        <property name="prefix">
            <value>/WEB-INF/views/</value>
        </property>
        <property name="suffix">
            <value>.jsp</value>
        </property>
    </bean>
</beans>

这是我的 web.xml

    <?xml version="1.0" encoding="UTF-8"?>
<web-app
    xsi:schemaLocation="http://java.sun.com/xml/ns/javaee         http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
    version="2.5">
      <filter>
     <filter-name>encoding-filter</filter-name>
     <filter-class>
  org.springframework.web.filter.CharacterEncodingFilter
     </filter-class>
     <init-param>
  <param-name>encoding</param-name>
  <param-value>UTF-8</param-value>
     </init-param>
     <init-param>
     <param-name>forceEncoding</param-name>
     <param-value>true</param-value>
     </init-param>
 </filter>

 <filter-mapping>
     <filter-name>encoding-filter</filter-name>
     <url-pattern>/*</url-pattern>
 </filter-mapping>
    <display-name>Sample Spring Maven Project</display-name><!-- Spring MVC -->
    <servlet>
        <servlet-name>mvc-dispatcher</servlet-name>
        <servlet-class>org.springframework.web.servlet.DispatcherServlet
        </servlet-class>
        <load-on-startup>1</load-on-startup>
    </servlet> 
    <servlet-mapping>
        <servlet-name>mvc-dispatcher</servlet-name>
        <url-pattern>/</url-pattern>
    </servlet-mapping>
    <listener>
        <listener-class>org.springframework.web.context.ContextLoaderListener
        </listener-class>
    </listener>
    <jsp-config>
  <jsp-property-group>
    <url-pattern>*.jsp</url-pattern>
    <page-encoding>UTF-8</page-encoding>
  </jsp-property-group>
</jsp-config>
    <context-param>
        <param-name>contextConfigLocation</param-name>
        <param-value>
            /WEB-INF/mvc-dispatcher-servlet.xml,
            /WEB-INF/spring-security.xml
        </param-value>
    </context-param><!-- Spring Security -->
    <filter>
    <filter-name>MultipartFilter</filter-name>
    <filter-class>org.springframework.web.multipart.support.MultipartFilter</filter-class>
</filter>
    <filter>
        <filter-name>springSecurityFilterChain</filter-name>
        <filter-class>org.springframework.web.filter.DelegatingFilterProxy
        </filter-class>
    </filter>
    <filter-mapping>
    <filter-name>MultipartFilter</filter-name>
    <url-pattern>/*</url-pattern>
</filter-mapping>
    <filter-mapping>
        <filter-name>springSecurityFilterChain</filter-name>
        <url-pattern>/*</url-pattern>
    </filter-mapping>


</web-app>

0 个答案:

没有答案