Javaee中文乱码解决方法
post 中文乱码解决方式
接受数据的时候设置
request.setCharacterEncoding("utf-8");//编码必须和页面编码一致
页面设置
<%@page import="java.net.URLDecoder"%> <%@page import="org.apache.naming.java.javaURLContextFactory"%> <%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%> <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
get中文乱码
修改tomcat server.xml
增加 URIEncoding="utf-8" 设置编码
<Connector URIEncoding="utf-8" connectionTimeout="20000" port="8080" protocol="HTTP/1.1" redirectPort="8443"/>
实例:
<a href="ppsd.jsp?a=盘两条">654465465654</a>
Servlet 后台跳转页面url中有中文
response.sendRedirect("ppsd.jsp?a=46565464564"+URLEncoder.encode("阿斯顿发放","utf-8")+"99999");