jsp web应用中文化

jsp web应用中文化,包括过滤器,字符编码等 这个更好用


http://jakarta.apache.org/struts/tags-bean" prefix="bean"%>
http://jakarta.apache.org/struts/tags-html" prefix="html"%>
http://jakarta.apache.org/struts/tags-logic" prefix="logic"%>

[@more@]

web.xml设置字符过滤器,实质是个Servlet

encodefilter
com.util.EncodeFilter


encodefilter
/*

package com.util;

import javax.servlet.*;
import javax.servlet.http.*;
import java.io.*;
import java.util.*;

public class EncodeFilter extends HttpServlet implements Filter {
private FilterConfig filterConfig;

//Handle the passed-in FilterConfig
public void init(FilterConfig filterConfig) throws ServletException {
this.filterConfig = filterConfig;
}

//Process the request/response pair
public void doFilter(ServletRequest request, ServletResponse response, FilterChain filterChain) {

try {
// if(request.getCharacterEncoding().equals("ISO8859_1"))
request.setCharacterEncoding("gbk"); ----过滤器设置字符编码
filterChain.doFilter(request, response);
}
catch(ServletException sx) {
filterConfig.getServletContext().log(sx.getMessage());
}
catch(IOException iox) {
filterConfig.getServletContext().log(iox.getMessage());
}
}

//Clean up resources
public void destroy() {
}
}


http://jakarta.apache.org/struts/tags-bean" prefix="bean"%>
http://jakarta.apache.org/struts/tags-html" prefix="html"%>
http://jakarta.apache.org/struts/tags-logic" prefix="logic"%>

tomcat支持中文名的处理方式
在server.xml配置文件中:
maxThreads="150" minSpareThreads="25" maxSpareThreads="75"
enableLookups="false" redirectPort="8443" acceptCount="100"
connectionTimeout="20000" disableUploadTimeout="true" URIEncoding="utf-8"/> --设置URIEncoding字符charset
<!-- Note : To disable connection timeouts, set connectionTimeout value to 0 --&gt


jsp页面中设置
--最好使用UTF-8统一编码

设置HttpServletRequest对象字符编码
request.setCharacterEncoding("GB2312");--ActionServlet,通常使用过滤器更佳,预先处理所有HTTP请求
HttpServletRequest.setCharacterEncoding(String encoding);

response.setContentType("text/html;charset=GB2312")


appication.properties

native2ascii -encoding GB2312 application.prop application_zh_CN.properties
application_zh_CN.properties --中文显示Unicode编码
application_en.properties --英文直接显示

通用日志记录--日志消息级别 :FATAL,ERROR,WARN,INFO,DEBUG,TRACE,方法小写 commons-logging.properties
org.apache.commons.logging.Log
org.apache.commons.logging.LogFactory
public static Log getLog(Class clazz) throw LogConfigurationException

public static Log getLog(String name) throw LogConfigurationException

常用日志实现
Log4J日志器 classpath: log4j.properties
log4j.rootLogger=[p优先级],appenderName名字
Logger
Appender
日志级别DEBUG,INFO,WARN,FATAL
Layout

来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/9194732/viewspace-914999/,如需转载,请注明出处,否则将追究法律责任。

转载于:http://blog.itpub.net/9194732/viewspace-914999/

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值