struts中文的解决

最近发现在struts的配置文件中配置一个全局的控制就OK了
<controller nocache="true" inputForward="true" maxFileSize="2M"
   contentType="text/html;charset=gb2312"/>
一:国际化的解决方法:
1.拷贝ApplicationResources.properties为文件:ApplicationResources_zh.properties
2.修改ApplicationResources_zh.properties为中文
3.在应用到的JSP中使用ISO_8859_1<%@?page?contentType="text/html;?charset=ISO_8859_1"%>

搞定~~~~~~~

注意ISO_8859_1,?不要拼错了哦。^O^

如果是ISO-8859-1就不成啦~~~

验证发现ISO8859-1也成~~~~~~~~~~~~~~~~~~~~~~~~~~

二:从数据库中取数据的解决办法:
只要在应用到的JSP中使用gb2312就可以

三:请求的解决办法:
加过滤器,如下:

??? Request Filter
??? view.util.RequestFilter
???
????? encoding
????? UTF-8
???
???
????? ignore
????? true
???
?

?
??? Request Filter
??? action
?
package view.util;

import javax.servlet.*;
import java.io.IOException;

public class RequestFilter implements Filter {

??? protected String encoding = null;

??? protected FilterConfig filterConfig = null;

??? protected boolean ignore = true;

??? public void destroy() {

??????? this.encoding = null;
??????? this.filterConfig = null;

??? }

??? public void doFilter(ServletRequest request, ServletResponse response,
???????????????????????? FilterChain chain)
??? throws IOException, ServletException {

??????? if (ignore || (request.getCharacterEncoding() == null)) {
??????????? String encoding = selectEncoding(request);
??????????? if (encoding != null){
????????????? request.setCharacterEncoding(encoding);
??????????? }else{
????????????? request.setCharacterEncoding( "UTF-8" );
??????????? }
??????? }
??????? /*
??????? if ( encoding != null ) {
??????????????????? request.setCharacterEncoding( encoding ) ;
??????????????? } else {
??????????????????? request.setCharacterEncoding( "UTF-8" ) ;
??????????????? }
??????? */
??????? chain.doFilter(request, response);

??? }

??? public void init(FilterConfig filterConfig) throws ServletException {

??? this.filterConfig = filterConfig;
??????? this.encoding = filterConfig.getInitParameter("encoding");
??????? String value = filterConfig.getInitParameter("ignore");
??????? if (value == null)
??????????? this.ignore = true;
??????? else if (value.equalsIgnoreCase("true"))
??????????? this.ignore = true;
??????? else if (value.equalsIgnoreCase("yes"))
??????????? this.ignore = true;
??????? else
??????????? this.ignore = false;

??? }

??? protected String selectEncoding(ServletRequest request) {

??????? return (this.encoding);

??? }

}

相关报到请看:http://www.javaresearch.org/forum/thread.jsp?column=20&thread=2281

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值