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可以防止获取表单数据为中文时乱码

  • 相关阅读:
    httpd添加新模块
    编译httpd细节
    apache配置文件说明及一些指令
    xen原理
    EXSI的使用
    VMWare ESX server安装
    虚拟化技术
    Kvm命令集管理虚拟机
    RAID几种方式
    BZOJ1011 [HNOI2008]遥远的行星 【奇技淫巧】
  • 原文地址:https://www.cnblogs.com/modou/p/9700025.html
Copyright © 2011-2022 走看看