标签:coding print 数组 protocol logs 通过 redirect tchar color
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 }
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 }
标签:coding print 数组 protocol logs 通过 redirect tchar color
原文地址:http://www.cnblogs.com/rocker-pg/p/7680794.html