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"%>
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 -->
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/