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“);
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去设置语言
控件:commons-fileupload-1.2.1.jar
当上传文件的时候表单,表单这个写:
<form name="" action="xx.do" method="post" enctype="multipart/form-data"> <input type="file"> <input type="text" name="username"> </form>
这个时候获取username表单参数的时候,不能用request.getParameter(“username”),这个样无论如何获取到的都是null,这句需要控件来帮助获取值。
DiskFileItemFactory factory = new DiskFileItemFactory(); ServletFileUpload upload = new ServletFileUpload(factory); upload.setHeaderEncoding(request.getCharacterEncoding()); Map<String,String> paramMap = new HashMap<String,String>(6); try { List items = upload.parseRequest(req); Iterator itr = items.iterator(); String fileName=null; while (itr.hasNext()) { FileItem item = (FileItem) itr.next(); if(item.isFormField()) { String name = item.getFieldName(); String value = item.getString(request.getCharacterEncoding()); paramMap.put(name, value); } else { if (item.getName() != null && !item.getName().equals("")) { fileName = item.getName(); File file = new File(RESOURCE_PATH,fileName); item.write(file); paramMap.put("src", fileName); } } } } catch (FileUploadException e) { e.printStackTrace(); } catch (Exception e) { e.printStackTrace(); }
通过”item.isFormField()“来获取表单字段的值,同时itme.getString(request.getCharacterEncodring()).来解决字符乱码的问题。这个地方尤其要注意。