日期:2014-05-17  浏览次数:20622 次

JSP POST传参为何是ISO8859_1,
AAA 页面:
HTML code

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

<% response.setCharacterEncoding("UTF-8"); %>

<meta http-equiv="content-type" content="text/html; charset=UTF-8" />

<form action="BBB.jsp" method="post">
    <input type="submit" name="submit" value="中文" />
</form>




BBB 页面:
HTML code

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

<% request.setCharacterEncoding("UTF-8"); %>

<meta http-equiv="content-type" content="text/html; charset=UTF-8" />

<!-- 请问 #P1 为何乱码 -->
<p id="p1"><%=request.getParameter("submit")%></p>

<!-- 请问 #P2 为何要重建字符串?以前听说POST传参只需设置request编码,为什么是ISO8859_1?-->
<p id="p2"><%=new String(request.getParameter("submit").getBytes("ISO8859_1"), "UTF-8")%></p>



------解决方案--------------------
数据库应该没什么关系吧。难道是你编辑器的原因。你看看你的编辑器是什么编码?