Struts中文乱码问题


中文乱码问题要确保以下的编码都要统一:


1.JSP:

<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>

2.HTML:
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">

3.Tomcat:
<Connector port="8080" URIEncoding="utf-8" protocol="HTTP/1.1"
               connectionTimeout="20000"
               redirectPort="8443" />

<Connector port="8009" protocol="AJP/1.3" redirectPort="8443" URIEncoding="utf-8" />

4.Filter

package org.android.tool;

import java.io.IOException;

import javax.servlet.Filter;
import javax.servlet.FilterChain;
import javax.servlet.FilterConfig;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

public class EncodingFilter implements Filter
{

	private String encoding;
	FilterConfig filterConfig = null;
	public void init(FilterConfig filterconfig) throws ServletException
	{
		this.filterConfig = filterconfig;
		encoding = filterconfig.getInitParameter("encoding");

	}

	public void doFilter(ServletRequest request, ServletResponse response,
			FilterChain filterchain) throws IOException,
			ServletException
	{
		HttpServletRequest httpRequest = (HttpServletRequest) request;
		HttpServletResponse httpResponse = (HttpServletResponse) response;
		httpRequest.setCharacterEncoding(encoding);
		httpResponse.setCharacterEncoding(encoding);
		filterchain.doFilter(request, response);

	}

	public void destroy()
	{
		this.filterConfig = null;
	}

}
 <filter>
   <filter-name>EncodingFilter</filter-name>
		<filter-class>org.android.tool.EncodingFilter</filter-class> 
	<init-param>
    	<param-name>encoding</param-name>	
    	<param-value>utf-8</param-value>	
   </init-param>
</filter>


5.URL中:

<s:url action="listAllFilesAction" var="url" encode="false" escapeAmp="false">



你可能感兴趣的:(struts,String,filter,url,action,encoding)