代码非常简单,就是书上的两个小程序。
一个html的表单提交到jsp页面,然后现实提交内容,显示中文用户名。但是,不管怎样都是乱码。<html>
<head></head>
<body>
<form action="request_demo01.jsp">
  请输入信息:<input type="text" name="info"/>
  <input type="submit" value="提交">
</form>
</body>
</html>[code=Jsp]
<%@ page contentType="text/html" pageEncoding="GBK"%>
<html>
<head></head>
<body><% 
    request.setCharacterEncoding("GBK");
    String content=request.getParameter("info");
%>
<h2><%=content %></h2>
</body>
</html>
[/code]难道是不细心的问题么。我找了好久,不知道问题出在哪。

解决方案 »

  1.   

    form 表单 用post提交试试
      

  2.   

    html中也要加编码方式的设置,加在最上面
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">表单的方式,最好用form的post方式,不然得用编码给中文重新编码
      

  3.   

    html中也要加入编码方式的设置
    <meta http-equiv="Content-Type" content="text/html;charset=GBK">最好用post方式提交,不然还得在html中对中文进行编码。我以前做的一个例子
        --jsp中--
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    var opinion = document.getElementById("opinion").value;//表示意见
    encodeURIComponent(encodeURIComponent(opinion)) //最后用get方式提交时,重新编码    --java中--
    String opinion = "";
    try {
    opinion = java.net.URLDecoder.decode(request.getParameter("opinion "), "UTF-8");
    } catch (UnsupportedEncodingException e1) {
    e1.printStackTrace();
    }
      

  4.   

    改post试试 !jsp的编码的gbk!html编码是?格式最好统一!