我做了一个ssh项目,由于疏忽,项目中js,jsp,java文件都用了不同的编码,有utf-8,gbk,iso8859-1,在自己的机子上项目做完了都没发现乱码问题,到了别的机子上就有了,经理让我把他编码统一成gbk。。我试过把其他格式的文件内容拷出来,然后删除旧的文件,新建一个同名的文件,设置编码为gbk,然后复制回内容,测试发现jsp填写的内容到了action就乱码了,搞了过滤器还是不行,怎么办?我在action加request.setCharacterEncoding("gbk");
response.setCharacterEncoding("gbk");还是不行
response.setCharacterEncoding("gbk");还是不行
解决方案 »
- Java服务器端,获取手持采集器(winCE系统,C# client)上的数据
- hibernate问题,帮忙看看啊
- SpringMVC和Struts是否有类似的作用?
- mybatis中删除关联表中的数据
- 穷人高分请教!~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~!!!555~``
- 在java中如何读取Oracle中的大字段,并且这个大字段的数据对应的是多个字段,如何保证按照这个顺序一一读写到这些字段中
- 请问128M内存可以运行Weblogic Server ?
- 一个XML,一个XSL。怎样按XSL显示XML,WUWUWU
- 请高手解决ejb编译错误
- 请问如何在tomcat里设置jvm的参数
- 超链接有中文,无法连接怎么办
- Struts2+Hibernate+Spring整合,有人懂没,真的没有一个人懂吗
<filter-name>encodingFilter</filter-name>
<filter-class>
org.springframework.web.filter.CharacterEncodingFilter
</filter-class>
<init-param>
<param-name>encoding</param-name>
<param-value>GBK</param-value>
</init-param>
</filter>
<filter-mapping>
<filter-name>encodingFilter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>这样就该好了吧。
如果spring的过滤器不行,建议你自己写个过滤器类
public class SetCharacterEncodingFilter implements Filter { protected FilterConfig filterConfig;
protected String encodingName;
protected boolean enable; public SetCharacterEncodingFilter() {
encodingName = "GBK";
enable = false;
} // 初始化
public void init(FilterConfig filterConfig) throws ServletException {
this.filterConfig = filterConfig;
} // 每个请求设置
public void doFilter(ServletRequest request, ServletResponse response,
FilterChain chain) throws IOException, ServletException {
request.setCharacterEncoding("GBK");
response.setCharacterEncoding("GBK");
chain.doFilter(request, response); } public void destroy() {
}
}
<filter>
<filter-name>SetCharacterEncodingFilter</filter-name>
<filter-class>
tools.SetCharacterEncodingFilter
</filter-class>
<init-param>
<param-name>encoding</param-name>
<param-value>gbk</param-value>
</init-param>
</filter>
<filter-mapping>
<filter-name>SetCharacterEncodingFilter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping> <filter-mapping>
<filter-name>SetCharacterEncodingFilter</filter-name>
<url-pattern>*.do</url-pattern>
</filter-mapping>你看我的过滤器有什么问题吗?
我测试过,他每次请求都进来的,乱码问题还是没解决
request.setCharacterEncoding("gbk");
response.setCharacterEncoding("gbk");
之后在Struts配置文件里配置<controll processclass="...."/>
应该就可以了,,,
可是我已经写了一个<controller processorClass="org.springframework.web.struts.AutowiringRequestProcessor"></controller>
再写一个控制器,会报错的。。怎么办
1、把所有文件不管是js,jsp,java都用记事本打开,复制到一个新建的文件中。
2、form用post
我以前改过我的myeclipse的编码设置,结果我的工程拷到别人的机子上之后,汉字都乱码了,中能一个个的文件用记事本打开再覆盖了。也是很麻烦的。