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