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 = " \n";
25         out.println(docType +
26                 "\n" +
27                 "" + title + "\n" +
28                 "\n" +
29                 "

" + title + "

\n" + 30 "
    \n" + 31 "
  • 站点名:" 32 + name.split("=")[1] + "\n" + 33 "
  • 网址:" 34 + request.getParameter("url") + "\n" + 35 "
\n" + 36 ""); 37 } 38 39 // 处理 POST 方法请求的方法 40 public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { 41 doGet(request, response); 42 } 43 }

解决方法在 21,22行

GET乱码(2)_第1张图片

 

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

转载于:https://www.cnblogs.com/AI-Cobe/p/9290594.html

你可能感兴趣的:(GET乱码(2))