0
如果任何用户访问我的网站可以查看我的网站使用不同的语言,所以我选择了3种语言英语,法语,他加禄语使用Spring国际化,我编码,但是当我点击法语或他加禄语链接语言改为两者之一,但仍然保持英文。程序编译和运行时没有任何错误,但语言不会分别更改为法语和他加禄语。 如果需要任何信息,我已准备好提供。如何使用spring的国际化?
messages_en.properties
student.title=Student List
student.id=Student ID
student.firstname=First name
student.lastname=Last name
student.year=Year
messages_fr.properties
student.title=Liste des étudiants
student.id=carte d'étudiant
student.firstname=prénom
student.lastname=nom de famille
student.yearLevel=Niveau année
messages_tl.properties
student.title=Listahan ng mga Magaaral
student.id=Numero ng magaaral
student.firstname=Pangalan
student.lastname=Apelyido
student.yearLevel=Antas
弹簧servlet.xml中
<!-- Spring Internationalizations -->
<bean id="messageSource"
class="org.springframework.context.support.ReloadableResourceBundleMessageSource">
<property name="basename" value="classpath:messages" />
<property name="defaultEncoding" value="UTF-8" />
</bean>
<bean id="localeResolver"
class="org.springframework.web.servlet.i18n.CookieLocaleResolver">
<property name="defaultLocale" value="en" />
</bean>
<bean id="localeChangeInterceptor"
class="org.springframework.web.servlet.i18n.LocaleChangeInterceptor">
<property name="paramName" value="language" />
</bean>
<bean id="handlerMapping"
class="org.springframework.web.servlet.mvc.annotation.DefaultAnnotationHandlerMapping">
<property name="interceptors">
<ref bean="localeChangeInterceptor" />
</property>
</bean>
student.jsp
<title>Student Management</title>
</head>
<body>
Language: <a href="./?language=en">English</a> | <a href="./?language=tl">Tagalog</a> | <a href="./?language=fr">French</a>
<h1><spring:message code="student.title" /></h1>
<form:form action="student.do" method="POST" commandName="student">
<table>
<tr>
<td><spring:message code="student.id" /></td>
<td><form:input path="studentid" /></td>
</tr>
<tr>
<td><spring:message code="student.firstname" /></td>
<td><form:input path="firstname" /></td>
</tr>
<tr>
<td><spring:message code="student.lastname" /></td>
<td><form:input path="lastname" /></td>
</tr>
<tr>
<td><spring:message code="student.year" /></td>
<td><form:input path="year" /></td>
</tr>
<tr>
<td>Date</td>
<td><div class="col-md-12">
<input type="date" class="def-input" placeholder="Your Date of Birth!">
</div>
</td>
</tr>
<tr>
<td colspan="2">
<input type="submit" name="action" value="Add" />
<input type="submit" name="action" value="Edit" />
<input type="submit" name="action" value="Delete" />
<input type="submit" name="action" value="Search" />
</td>
</tr>
</table>
</form:form>
<br>
<table border="1">
<th><spring:message code="student.id" /></th>
<th><spring:message code="student.firstname" /></th>
<th><spring:message code="student.lastname" /></th>
<th><spring:message code="student.year" /></th>
<c:forEach items="${studentlist}" var="student">
<tr>
<td>${student.studentid}</td>
<td>${student.firstname}</td>
<td>${student.lastname}</td>
<td>${student.year}</td>
</tr>
</c:forEach>
</table>
我提供工作空间路径InternBridge \ com \ internbridge \ resources。在资源文件夹中.properties文件存在。你在问这个还是其他的问题? –
是的,我在找什么...所以尝试创建一个消息文件夹到资源中,并通过value =“classpath:messages/messages”替换value =“classpath:messages” – Skykaza
我编辑了答案,请一次点击上面的项目视图链接,在这个资源下,我创建了正常的文件夹命名消息,但它是作为包视图创建的,为什么会发生这种情况?我保存了.properties文件,它不工作,请帮助我。 –