springMVC国际化语言无法切换:
跳转jsp,国际化语言无法切换
controller,调转jsp语言就可以切换
暂时不知道什么原因,以后找出了补上答案
springMVC国际化语言无法切换:
跳转jsp,国际化语言无法切换
controller,调转jsp语言就可以切换
暂时不知道什么原因,以后找出了补上答案
1. 首先初始化grid {
datatype:”local“,
}
2. 加载数据
$.post(url,data,function(data) {
gird.clearGridData();
gird.setGridParam({data: data.rows}); //数据格式就是json的rows的数据
gird.trigger(“reloadGrid”, [{page:1}]);
},’json’)
3. 如何获取所有数据,如果是编辑,获取编辑后的数据
gird.getGridParam(“data”)
1. 单元格编辑
2. 编辑相关的事件
shrinkToFit:false,
altRows: true, //显示行号
loadonce:true, //加载一次
loadAllData:true, //自定义的
autowidth: true, //宽度自适应
autoScroll:true, //自动显示滚动条
cellsubmit: ‘clientArray’, 编辑的时候,客户端事件
cellEdit:true,
afterEditCell:function(rowid, cellname, value, iRow, iCol) {
},
afterSaveCell:function(rowid, cellname, value, iRow, iCol) {
},
JAVA写js文件,获取json数据乱码问题
解决方案,写入文件时要以UTF-8的形式写入,不然将会出现乱码
FileUtils.writeStringToFile(new File(jsFile), sb.toString(),”UTF-8“);
Courage
John Fitzgerald Kennedy
The courage of life is often a less dramatic spectacle than the courage of a final moment; but it is no less a magnificent mixture of triumph and tragedy. A man does what he must—in spite of personal consequences, in spite of obastacles and dangers and pressures— and that is the basis of human morality.
To be courageous…requires no exceptional qualifications, no magic formula, no special combination of time, place and circumstances. It is an opportunity that sooner or later is presented to us all. Politics merely furnishes one arena of life which imposes special tests of courage. In whatever arena of life one may meet the challenge of courage, whatever may be the sacrifices he faces if he follows his own conscience—the loss of his friends, his fortune, his contentment, even the esteem of his fellow men—each man must decide for himself the course he will follow. The stories of past courage can define that ingredient—they can teach, they can offer hope, they can provide inspiration. But they can not supply courage itself. For this each man must look into his own soul.
1. 配置bean,增加spring对国际化的支持 ReloadableResourceBundleMessageSource
2. 资源文件 messages_zh_CN.properties
3. 使用国际化 <s:message code=”hello”/> context.getMessage(“hello”);
spring-service.xml,之前在spring-web.xml,导致获取不到bean
<bean id=”messageSource”
class=”org.springframework.context.support.ReloadableResourceBundleMessageSource”>
<property name=”basenames”>
<list>
<value>classpath:/messages</value>
</list>
</property>
<property name=”defaultEncoding” value=”UTF-8″ />
<property name=”useCodeAsDefaultMessage” value=”true”></property>
</bean>
<bean id=”localeResolver” class=”org.springframework.web.servlet.i18n.SessionLocaleResolver”>
<property name=”defaultLocale” value=”zh_CN”></property>
</bean>
spring-web.xml 语言切换的时候拦截
<mvc:interceptors>
<bean id=”localeChangeInterceptor”
class=”org.springframework.web.servlet.i18n.LocaleChangeInterceptor”>
<property name=”paramName” value=”lang” />
</bean>
</mvc:interceptors>
资源文件在resources目录下,直接在classpath下
使用:jsp:标签使用,java:上下文.getMessage()
错误分析:
1. 加载资源文件的时候,会去判断beanFactory中有没有包含bean id=”messageSource”的bean,这也是为什么ReloadableResourceBundleMessageSource类的bean的id一定要为“messageSource”。这个时候可以通过beanFactory.getBeanDefinition(“messageSource”),如果没有包含,则不走if语句,spring就没有加载资源文件,那么当你在使用<s:message code=”hello”/>
将会报错:No message found under code ‘title’ for locale ‘zh_CN’, 换句话说此错误是没有加载到bean messageSource。
2. 语言切换无效。通过地址栏http://localhost:8080/page/index.jsp?lang=en
地址栏请求是*.jsp,参照tomcat home/conf/web.xml截图
所有的*.jsp 会被tomcat容器拦截,根据servlet匹配原则,就不会走DispatcherServlet,就不会走拦截器LocaleChangeInterceptor,所以设置语言无效。
方案:
现在将切换语言的功能通过访问controller
http://localhost:8080/page/index?lang=en
让拦截LocaleChangeInterceptor去设置语言