spring mvc4 动态切换语言不起作用
我利用 SPRING4 MVC配置了动态切换语言,但是在页上点击中文、英文切换的时候不起作用。请高手看看spring - 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:p="http://www.springframework.org/schema/p"
xmlns:mvc="http://www.springframework.org/schema/mvc"
xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="
http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context.xsd
http://www.springframework.org/schema/mvc
http://www.springframework.org/schema/mvc/spring-mvc.xsd">
<!-- <mvc:annotation-driven>
<mvc:message-converters register-defaults="true">
<bean class="org.springframework.http.converter.StringHttpMessageConverter">
<property name="supportedMediaTypes" value="text/plain;charset=UTF-8"/>
</bean>
</mvc:message-converters>
</mvc:annotation-driven> -->
<!-- 启用Spring MVC注解功能 -->
<mvc:annotation-driven/>
<!-- 启动Srping组件自动扫描机制,Spring会自动扫描base-package包及其子包下面的类 -->
<context:component-scan base-package="com.efs.business"/>
<!-- 设置视图解析类,使用默认的JSTL解析器 -->
<bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="prefix" value="/WEB-INF/jsp"/>
<property name="suffix" value=".jsp"/>
<property name="viewClass" value="org.springframework.web.servlet.view.JstlView" />
</bean>
<!-- 系统配置易做图 -->
<mvc:interceptors>
<!-- 切换语言易做图 -->
<mvc:interceptor>
<mvc:mapping path="/*"/>
<ref bean="localeChangeInterceptor"/>
</mvc:interceptor>
</mvc:interceptors>
<!-- 配置国际化资源文件,包括动态切换 START -->
<bean id="messageSource" class="org.springframework.context.support.ResourceBundleMessageSource">
<property name="basename" value="com.efs.resource.Message"/>
</bean>
<bean id="localeResolver" class="org.springframework.web.servlet.i18n.SessionLocaleResolver">
</bean>
<bean id="localeChangeInterceptor" class="org.springframework.web.servlet.i18n.LocaleChangeInterceptor">
<property name="paramName" value="locale"/>
</bean>
<!-- 配置国际化资源文件,包括动态切换 END -->
</beans>
切换Controller:
package com.efs.business.locale;
import java.util.Locale;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.LocaleResolver;
@Controller
@RequestMapping("/locale")
public class SysLocaleController
{
@Autowired
private LocaleResolver localeResolver;
@RequestMapping("/changeLocale")
public String changeLocale(String locale,HttpServletRequest request,HttpServletResponse response)
{
Locale l = new Locale(locale);
localeResolver.setLocale(request, response, l);
return "redirect:/demo/index.do";
}
}
HTML页面:
<a href="<%=basePath%>/locale/changeLocale.do?locale=zh_CN">中文</a> |
<a href="<%=basePath%>/locale/changeLocale.do?locale=en_US">English</a>
<hr/>
<form action="<%=basePath%>/demo/login.do" method="post" id="form">
<!-- 页面上使用资源国际化 -->
<sf:message code="demo.label.userName" />:<input type="text" name="userName" value="${form.userName }" />
<br/>
<sf:message code="demo.label.password" />:<input type="password" name="password" /><br/>
--------------------编程问答-------------------- 这么早就玩上了4了?有什么新特性
--------------------编程问答-------------------- 难道没有人碰到这种问题吗
补充:Java , Java EE