一.HttpServeltRequest:
1)获取表单数据
2)获取报头信息
3)其他方法:
localhost或者127.0.0.1 本机
二. HttpServletResponse:
1.向客户端输出信息
setContentType("") 浏览器的打开方式 mime
getWriter():字符流响应
getOutputStream():字节流响应 (图片、视频、音频、pdf等)
<mime-mapping>
<extension>html</extension>
<mime-type>text/html</mime-type>
</mime-mapping>
2.中英文乱码 ISO-8859-1
中文的编码: UTF-8 GB2312 GBK GB18030
请求时乱码:
响应时乱码:
数据库乱码: mysql
post方式提交:
1)username=new String(username.getBytes("ISO-8859-1"),"UTF-8");
1)获取表单数据
2)获取报头信息
3)其他方法:
localhost或者127.0.0.1 本机
二. HttpServletResponse:
1.向客户端输出信息
setContentType("") 浏览器的打开方式 mime
getWriter():字符流响应
getOutputStream():字节流响应 (图片、视频、音频、pdf等)
<mime-mapping>
<extension>html</extension>
<mime-type>text/html</mime-type>
</mime-mapping>
2.中英文乱码 ISO-8859-1
中文的编码: UTF-8 GB2312 GBK GB18030
请求时乱码:
响应时乱码:
数据库乱码: mysql
post方式提交:
response.setContentType("text/html;charset=utf-8");
request.setCharacterEncoding("utf-8");
或者
request.setCharacterEncoding("utf-8");
response.setCharacterEncoding("UTF-8");
get方式提交:1)username=new String(username.getBytes("ISO-8859-1"),"UTF-8");
2)修改Tomcat服务器:
<Connector port="8080" protocol="HTTP/1.1" connectionTimeout= "20000" redirectPort="8443" URIEncoding="UTF-8"/>