当前位置: 代码迷 >> Java Web开发 >> 为什么用get会乱码,而用post不会乱码,该怎么解决
  详细解决方案

为什么用get会乱码,而用post不会乱码,该怎么解决

热度:156   发布时间:2016-04-17 10:16:06.0
为什么用get会乱码,而用post不会乱码
ex8-01.html
HTML code
<?xml version="1.0" encoding="UTF-8" ?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml">    <head>        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />        <title>获取客户提交的信息案例</title>    </head>        <body>        <div class="zjfclass" align="center">            <form action="ex8-02.jsp" method="post">                <table>                    <tr>                        <td>                            姓名:                        </td>                        <td>                            <input name="name" />                        </td>                    </tr>                    <tr>                        <td>                            电话:                        </td>                        <td>                            <input name="phone" />                        </td>                    </tr>                    <tr>                        <td colspan="2" align="center">                            <input type="submit" value="提交" name="submit" />                        </td>                    </tr>                </table>            </form>        </div>    </body></html>

ex8-02.jsp
HTML code
<?xml version="1.0" encoding="UTF-8" ?><%@ page language="java" contentType="text/html; charset=UTF-8"    pageEncoding="UTF-8"%><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml">    <head>        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />        <title>request对象常用方法应用案例</title>    </head>        <body>        <%            request.setCharacterEncoding("UTF-8");            out.println("姓名文本框提交信息:" + request.getParameter("name") + "<br />");            out.println("电话文本框提交信息:" + request.getParameter("phone") + "<br />");            out.println("客户端协议名和版本号:" + request.getProtocol() + "<br />");            out.println("客户机名:" + request.getRemoteHost() + "<br />");            out.println("客户机的IP地址:" + request.getRemoteAddr() + "<br />");            out.println("客户提交信息的长度:" + request.getContentLength() + "<br />");            out.println("客户提交信息的方式:" + request.getMethod() + "<br />");            out.println("HTTP头文件中的Host值:" + request.getHeader("Host") + "<br />");            out.println("服务器名:" + request.getServerName() + "<br />");            out.println("服务器端口号:" + request.getServerPort() + "<br />");            out.println("客户请求页面的文件目录:" + request.getServletPath() + "<br />");        %>    </body></html>

上面这两个文件太奇怪了,当我在ex8-01.html中用post的时候,输入中文按确定完全正常,当我用get的时候,输入中文按确定却出现乱码,这个太神奇了,求解释

------解决方案--------------------
  相关解决方案