1, SQL Server: JNDI JDBC: Microsoft: SQLServer: // localhost: 1433; DatabaseName = DATA Container: Default installation Tomcat5.0 IDE: Utf-8 encoding, JSP, Java files are UTF-8
Properties file: Transfer to GBK Native2ASCII -Encoding GBK ApplicationResources_GBK.Properties ApplicationResources_zh-cn.properties
Web.xml file: UTF-8
Encodingfilter class package com.vfrankmusic.sysinfo;
import javax.servlet.ServletException; import javax.servlet.Filter; import javax.servlet.FilterChain; import javax.servlet.FilterConfig; import javax.servlet.ServletRequest; import javax.servlet.ServletResponse; import javax.servlet.http.HttpServletRequest Import java.io.ioException; // Import javax.servlet.ServletContext; // Import javax.servlet.http.httpsession; // Import javax.servlet.http.httpservletResponse;
/ ** *
Title: MusicWeb p> *
Description: MusicWeb Site P> *
Copyright: Copyright (c) 2004 p> *
Company: vfranksoft P> * @author Wu Xiaolong * @version 1.0 * /
public class EncodingFilter implements Filter {private FilterConfig config = null; // default to ASCII private String targetEncoding = "ASCII"; public void init (FilterConfig config) throws ServletException {this.config = config; this.targetEncoding = config.getInitParameter ( " encoding ");} public void destroy () {config = null; targetEncoding = null;} public void doFilter (ServletRequest srequest, ServletResponse sresponse, FilterChain chain) throws IOException, ServletException {HttpServletRequest request = (HttpServletRequest) srequest; request.setCharacterEncoding ( Targetencoding; // move on to the next chain.dofilter (Srequest, SRESPONSE);}}
2, MySQL: JNDI jdbc: mysql: // localhost: 3306 / data useUnicode = & characterEncoding = UTF-8 important true, mysql establishing a database CREATE DATABASE table name DEFAULT CHARACTER SET utf8 COLLATE utf8_general_ci; container:? Ditto IDE: ditto Properties: ditto Web.xml: