zoukankan      html  css  js  c++  java
  • 表单提交中文时出现乱码

    下面是一个提交页面(submit.jsp),代码如下:

      
    <html>
      <head>
      <title>JSP的中文处理</title>
      <meta http-equiv="Content-Type" content="text/html; charset=gb2312">
      </head>
      <body>
      <form name="form1" method="post" action="process.jsp">
      <div align="center">
      <input type="text" name="name">
      <input type="submit" name="Submit" value="Submit">
      </div>
      </form>
      </body>
      </html>
      //下面是处理页面(process.jsp)代码:
      <%@ page contentType="text/html; charset=gb2312"%>
      <html>
      <head>
      <title>JSP的中文处理</title>
      <meta http-equiv="Content-Type" content="text/html; charset=gb2312">
      </head>
      <body>
      <%=request.getParameter("name")%>
      </body>
      </html>
    

      

      如果submit.jsp提交英文字符能正确显示,如果提交中文时就会出现乱码。原因:浏览器默认使用UTF
      -8编码方式来发送请求,而UTF- 8和GB2312编码方式表示字符时不一样,这样就出现了不能识别字符。
      解决办法:通过request.seCharacterEncoding ("gb2312")对请求进行统一编码,就实现了中文的正常
      显示。修改后的process.jsp代码如下:
      
    <%@ page contentType="text/html; charset=gb2312"%>
      <%
      request.setCharacterEncoding("gb2312");
      %>
      <html>
      <head>
      <title>JSP的中文处理</title>
      <meta http-equiv="Content-Type" content="text/html; charset=gb2312">
      </head>
      <body>
      <%=request.getParameter("name")%>
      </body>
      </html>
  • 相关阅读:
    cf415D Mashmokh and ACM(DP)
    [USACO]EulerianTour (欧拉通路)
    hdu2544 (SPFA)
    hdu2544 (bellman-ford)
    [TC]SRM615 div1 250 AmebaDiv1
    Step By Step (zz from UESTC)
    [USACO]Sweet Butter 多种解法
    Node.js权威指南 (3)
    Web开发常见问题荟萃
    比较vue.js react.js angular.js
  • 原文地址:https://www.cnblogs.com/amwuau/p/6210529.html
Copyright © 2011-2022 走看看