विषय विषय में है - मुझे पता नहीं चल सकता है कि मेरे स्प्रिंग एमवीसी एप्लिकेशन में स्थानीय लोगों के साथ क्या समस्या है। एक ट्यूटोरियल के रूप में मैं उस link + का उपयोग कर रहा था + मैंने Google में मिली विभिन्न भिन्नताओं को आजमाया है। जब मैं भाषा को बदलने के लिए अपने वेब पेज लिंक पर क्लिक करता हूं तो स्ट्रिंग ?lang=XX
पते पर जोड़ा जा रहा है, लेकिन कुछ भी नहीं होता है।वसंत का स्थानीयकरण भाषा स्विच नहीं करता
यहाँ मेरी सर्वलेट-context.xml
<?xml version="1.0" encoding="UTF-8"?>
<beans:beans xmlns="http://www.springframework.org/schema/mvc"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:beans="http://www.springframework.org/schema/beans"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:lang="http://www.springframework.org/schema/lang"
xsi:schemaLocation="http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-3.0.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">
<!-- DispatcherServlet Context: defines this servlet's request-processing infrastructure -->
<!-- Enables the Spring MVC @Controller programming model -->
<annotation-driven />
<!-- Handles HTTP GET requests for /resources/** by efficiently serving up static resources in the ${webappRoot}/resources directory -->
<resources mapping="/resources/**" location="/resources/" />
<!-- Resolves views selected for rendering by @Controllers to .jsp resources in the /WEB-INF/views directory -->
<beans:bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<beans:property name="prefix" value="/WEB-INF/views/" />
<beans:property name="suffix" value=".jsp" />
</beans:bean>
<context:component-scan base-package="ua.dod.picload.web" />
<!-- Internalization and localization support -->
<beans:bean id="messageSource"
class="org.springframework.context.support.ReloadableResourceBundleMessageSource">
<beans:property name="basename" value="classpath:message" />
<beans:property name="defaultEncoding" value="UTF-8"/>
</beans:bean>
<beans:bean id="localeChangeInterceptor"
class="org.springframework.web.servlet.i18n.LocaleChangeInterceptor">
<beans:property name="paramName" value="lang" />
</beans:bean>
<beans:bean class="org.springframework.web.servlet.handler.SimpleUrlHandlerMapping">
<beans:property name="interceptors">
<beans:ref bean="localeChangeInterceptor" />
</beans:property>
</beans:bean>
<beans:bean id="localeResolver"
class="org.springframework.web.servlet.i18n.SessionLocaleResolver">
<beans:property name="defaultLocale" value="en"/>
</beans:bean>
</beans:beans>
मेरे नियंत्रक है:
package ua.dod.picload.web;
import java.util.Map;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
@Controller
public class IndexController {
@RequestMapping("/index")
public String listIndex(Map<String, Object> map) {
return "index";
}
@RequestMapping("/")
public String home() {
return "redirect:/index";
}
}
index.jsp
<%@ page language="java" contentType="text/html; charset=utf8" pageEncoding="utf8"%>
<%@taglib uri="http://www.springframework.org/tags" prefix="spring"%>
<%@taglib uri="http://www.springframework.org/tags/form" prefix="form"%>
<%@taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf8">
<title><spring:message code="label.title" /></title>
</head>
<body>
<span style="float: right">
<a href="?lang=en">en</a>
<a href="?lang=ru">ru</a>
</span>
<spring:message code="label.body" />
</body>
</html>
और मैं messages_en.properties
और मेरे src/main/resources
निर्देशिका में messages_ru.properties
है। जाहिर है, मैंने कुछ विवरण याद किए हैं, लेकिन मैं निश्चित रूप से समस्या को पकड़ नहीं सकता। बीटीडब्ल्यू, जब मैं <beans:property name="defaultLocale" value="en"/>
में मान बदल रहा हूं तो भाषाएं ठीक से बदलती हैं। हम सच में आपकी मदद की सराहना करेंगे।
धन्यवाद कोड की है कि ब्लॉक जोड़ने मेरे लिए काम किया: - यदि आप अपने डिफ़ॉल्ट implementaion ओवरराइड करना चाहते आप कुछ इंटरसेप्टर के साथ प्रदान करना चाहते हैं आपके मामले में, आपको लगता है कि इस तरह से अपनी इंटरसेप्टर सेम पंजीकरण से कर सकते हैं ! –
मेरे लिए भी काम किया !! धन्यवाद –
मेरे लिए काम किया ...! – madhairsilence