zoukankan      html  css  js  c++  java
  • jsp乱码

    在jsp文件中:

    <%@page import="java.net.URLEncoder"%>
    <%@ page language="java" contentType="text/html; charset=utf-8"
        pageEncoding="utf-8"%>
    <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
    <html>
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
    <title>Insert title here</title>
    </head>
    <body>
    <a href="/WebProject/GetEncodingServlet?name=<%=URLEncoder.encode("中国", "utf-8") %>">get乱码问题</a>
    </body>
    </html>

    java文件:

    protected void doGet(HttpServletRequest req, HttpServletResponse resp)
                throws ServletException, IOException {
            //req.setCharacterEncoding("utf-8");
            String name = req.getParameter("name");
            byte data[] = name.getBytes("iso-8859-1");
            String encodingName = new String(data,"utf-8");
            System.out.println("encodingName="+encodingName);
            System.out.println("name="+name);
        }

    get乱码:

    String name = new String(request.getParameter("input").getBytes("ISO-8859-1"),"utf-8");

    post乱码:

    request.setCharacterEncoding("utf-8");
    response.setContentType("text/html;charset=utf-8");

  • 相关阅读:
    bootstrap多选框
    window.open()总结
    sql游标及模仿游标操作
    表变量及临时表数据批量插入和更新 写法
    表变量类型的创建及使用
    事物及exec
    [NOI2017]蚯蚓排队
    [NOI2017]游戏
    [NOI2017]蔬菜
    luogu P4194 矩阵
  • 原文地址:https://www.cnblogs.com/mada0/p/4789708.html
Copyright © 2011-2022 走看看