zoukankan      html  css  js  c++  java
  • 使用jsp内置对象request获取表单提交中文内容乱码的解决办法

    page1.jsp

    <%@ page language="java" contentType="text/html; charset=UTF-8"
        pageEncoding="UTF-8"%>
    <html>
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <title>page1</title>
    </head>
    <body>
    <form action="page1_1.jsp" method="post">
    <input type="text" name="username" />
    <input type="password" name="userpwd" />
    <input type="submit" value="提交" />
    </form>
    </body>
    </html>

    page1_1.jsp

    <%@ page language="java" contentType="text/html; charset=UTF-8"
        pageEncoding="UTF-8"%>
    <html>
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <title>page1_1</title>
    </head>
    <body>
    <%
    request.setCharacterEncoding("utf-8");
    String username = request.getParameter("username");
    String userpwd = request.getParameter("userpwd");
    out.println("username:" + username + "<br/>");
    out.println("userpwd:" + userpwd + "<br/>");
    %>
    </body>
    </html>

    从page1.jsp页面提交表单到page1_1.jsp页面,注意看page1_1.jsp标红的内容,设置request编码方式为utf-8可以防止获取表单数据为中文时乱码

  • 相关阅读:
    005. gitlab安装
    004. github使用
    003. git标签
    TS标红和报错解决(优化项)
    catalog连接数据库与sde权限问题
    博客新生企划
    HDU 7105 Power Sum
    HDU 7131 Nun Heh Heh Aaaaaaaaaaa
    BZOJ 1691 挑剔的美食家
    洛谷 4254 Blue Mary 开公司
  • 原文地址:https://www.cnblogs.com/modou/p/9700025.html
Copyright © 2011-2022 走看看