標籤:coding print 數組 protocol logs 通過 redirect tchar color
GET方式提交參數分析
code.jsp
1 <%@ page language="java" contentType="text/html; charset=UTF-8" 2 pageEncoding="UTF-8"%> 3 <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> 4 <html> 5 <head> 6 <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> 7 <title>Insert title here</title> 8 </head> 9 <body>10 <form action="${pageContext.request.contextPath}/doget" method="get">11 <input type="text" name="name">12 <input type="submit" value="提交">13 </form>14 </body>15 </html>
DoGetServlet
1 <Connector connectionTimeout="20000" port="88" protocol="HTTP/1.1" redirectPort="8443">
1 protected void doGet(HttpServletRequest request, HttpServletResponse response) 2 throws ServletException, IOException { 3 //URL的組成 4 //網域名稱:連接埠/contextPath/servletPath/pathInfo?queryString 5 6 //1.不加處理獲得的請求參數,獲得的結果為"ISO-8859-1"解碼後的參數 7 String name1 = request.getParameter("name"); 8 System.out.println(name1); //name1 = ??????? 9 10 //2.先用"ISO-8859-1"進行編碼,再用"UTF-8"進行解碼11 String name2 = URLEncoder.encode(request.getParameter("name"), "iso-8859-1");12 name2 = URLDecoder.decode(name2, "utf-8");13 System.out.println(name2); //name2 = 啊啊啊14 15 //3.用String的建構函式對獲得的請求參數進行處理, 16 //通過使用指定的 charset 解碼指定的 byte 數組,17 //構造一個新的 String。18 String name3 = 19 new String(request.getParameter("name").getBytes("iso-8859-1"),"utf-8");20 System.out.println(name3); //name3 = 啊啊啊21 22 }
1 <Connector connectionTimeout="20000" port="88" protocol="HTTP/1.1" redirectPort="8443" URIEncoding="UTF-8"/>
1 protected void doGet(HttpServletRequest request, HttpServletResponse response) 2 throws ServletException, IOException { 3 //URL的組成 4 //網域名稱:連接埠/contextPath/servletPath/pathInfo?queryString 5 6 //1.不加處理獲得的請求參數,獲得的結果為"ISO-8859-1"解碼後的參數 7 String name1 = request.getParameter("name"); 8 System.out.println(name1); //name1 = 啊啊啊 9 10 //2.先用"ISO-8859-1"進行編碼,再用"UTF-8"進行解碼11 String name2 = URLEncoder.encode(request.getParameter("name"), "iso-8859-1");12 name2 = URLDecoder.decode(name2, "utf-8");13 System.out.println(name2); //name2 = ???14 15 //3.用String的建構函式對獲得的請求參數進行處理, 16 //通過使用指定的 charset 解碼指定的 byte 數組,17 //構造一個新的 String。18 String name3 = 19 new String(request.getParameter("name").getBytes("iso-8859-1"),"utf-8");20 System.out.println(name3); //name3 = ???21 22 }
POST方式提交參數分析
code.jsp
1 <%@ page language="java" contentType="text/html; charset=UTF-8" 2 pageEncoding="UTF-8"%> 3 <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> 4 <html> 5 <head> 6 <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> 7 <title>Insert title here</title> 8 </head> 9 <body>10 <form action="${pageContext.request.contextPath}/doget" method="post">11 <input type="text" name="name">12 <input type="submit" value="提交">13 </form>14 </body>15 </html>
1 protected void doPost(HttpServletRequest request, HttpServletResponse response)2 throws ServletException, IOException {3 4 //1.不加處理獲得的請求參數,獲得的結果為"ISO-8859-1"解碼後的參數5 String name1 = request.getParameter("name");6 System.out.println(name1); //name1 = ???????7 8 }
1 protected void doPost(HttpServletRequest request, HttpServletResponse response)2 throws ServletException, IOException {3 4 //2.佈建要求參數為"UTF-8",獲得結果為"UTF-8"??解碼後的參數5 request.setCharacterEncoding("utf-8");6 String name2 = request.getParameter("name");7 System.out.println(name2); //name1 = 啊啊啊8 }
Java開發中的編碼分析__GET&POST