<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.6</source>
<target>1.6</target>
<encoding>UTF-8</encoding>
<compilerArguments>
<extdirs>src\main\webapp\WEB-INF\lib</extdirs>
</compilerArguments>
</configuration>
</plugin>
二、解决springmvc的get乱码问题
1.post处理乱码是这样的
<filter>
<filter-name>encodingFilter</filter-name>
<filter-class>org.springframework.web.filter.CharacterEncodingFilter</filter-class>
<async-supported>true</async-supported>
<init-param>
<param-name>encoding</param-name>
<param-value>UTF-8</param-value>
</init-param>
</filter>
<filter-mapping>
<filter-name>encodingFilter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
2.get乱码处理
public class EncodingFilter extends OncePerRequestFilter {
private String encoding;
public void setEncoding(String encoding) {
this.encoding = encoding;
}
@Override
protected void doFilterInternal(HttpServletRequest request, HttpServletResponse response, FilterChain chain)
throws ServletException, IOException {
// 设置请求响应字符编码
request.setCharacterEncoding(encoding);
response.setCharacterEncoding(encoding);
// 传递给目标servlet或jsp的实际上是动态代理的对象,而不是原始的HttpServletRequest对象
request = (HttpServletRequest) Proxy.newProxyInstance(request.getClass().getClassLoader(), request.getClass().getInterfaces(), new MyInvacationHandler(request));
chain.doFilter(request, response);
}
class MyInvacationHandler implements InvocationHandler{
private HttpServletRequest request;
MyInvacationHandler(HttpServletRequest request){
this.request=request;
}
@Override
public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
switch (method.getName()) {
case "getParameter":
String value = request.getParameter((String)args[0]);
try {
if(value != null){
value=new String(value.getBytes("ISO-8859-1"),encoding);
}
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
}
return value;
case "getParameterValues":
String[] values = request.getParameterValues((String)args[0]);
if (values != null) {
for (int i = 0; i < values.length; i++) {
try {
values[i] = new String(values[i].getBytes("ISO-8859-1"),encoding);
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
}
}
}
return values;
default:
return method.invoke(request, args);
}
}
}
}
web.xml配置
<filter>
<filter-name>encodingFilter12</filter-name>
<filter-class>com.wjw.controller.EncodingFilter</filter-class>
<init-param>
<param-name>encoding</param-name>
<param-value>utf-8</param-value>
</init-param>
</filter>
<filter-mapping>
<filter-name>encodingFilter12</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
tomcat class nofound,spring mvc的get请求乱码处理
原文:http://blog.51cto.com/10913595/2110718