zoukankan      html  css  js  c++  java
  • GET乱码(2)

     1 package six.four.five.web;
     2 
     3 import javax.servlet.ServletException;
     4 import javax.servlet.annotation.WebServlet;
     5 import javax.servlet.http.HttpServlet;
     6 import javax.servlet.http.HttpServletRequest;
     7 import javax.servlet.http.HttpServletResponse;
     8 import java.io.IOException;
     9 import java.io.PrintWriter;
    10 import java.net.URLDecoder;
    11 
    12 @WebServlet(name = "ServletDemo3")
    13 public class ServletDemo3 extends HttpServlet {
    14     protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
    15         // 设置响应内容类型
    16         response.setContentType("text/html;charset=UTF-8");
    17 
    18         PrintWriter out = response.getWriter();
    19         String title = "使用 GET 方法读取表单数据";
    20 //        String name =new String(request.getParameter("name").getBytes("ISO8859-1"),"UTF-8");
    21         String name1 = request.getQueryString();
    22         String name = URLDecoder.decode(name1, "UTF-8");
    23         // 处理中文
    24         String docType = "<!DOCTYPE html> 
    ";
    25         out.println(docType +
    26                 "<html>
    " +
    27                 "<head><title>" + title + "</title></head>
    " +
    28                 "<body bgcolor="#f0f0f0">
    " +
    29                 "<h1 align="center">" + title + "</h1>
    " +
    30                 "<ul>
    " +
    31                 "  <li><b>站点名</b>:"
    32                 + name.split("=")[1] + "
    " +
    33                 "  <li><b>网址</b>:"
    34                 + request.getParameter("url") + "
    " +
    35                 "</ul>
    " +
    36                 "</body></html>");
    37     }
    38 
    39     // 处理 POST 方法请求的方法
    40     public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
    41         doGet(request, response);
    42     }
    43 }

    解决方法在 21,22行

    具体参照了:https://blog.csdn.net/justloveyou_/article/details/57156039    和     https://blog.csdn.net/justloveyou_/article/details/57156039      和       https://blog.csdn.net/gg12365gg/article/details/52347214

  • 相关阅读:
    mysql 查询结果中增加序号
    mycat配置文件备份
    解决Python安装模块出错 ImportError: No module named setuptools
    sed 详解【转】
    CentOS下配置SFTP操作日志
    解决redis aof文件过大的问题
    mysql主从复制搭建中几种log和pos详解
    Linux下使用命令行配置IPMI
    Zabbix笔记
    zabbix_agentd.conf配置文件详解
  • 原文地址:https://www.cnblogs.com/AI-Cobe/p/9290594.html
Copyright © 2011-2022 走看看