您的位置:首页 > 产品设计 > UI/UE

day10 Request&Response

2016-03-13 00:00 399 查看

service(request,response)工作原理:



Response:

响应行:响应的协议 响应的状态码 响应的描述

响应头

响应正文

状态码,字节流,字符流:



注意:设置错误的要用:sendError()

重定向:





乱码:





验证码:

Request:

获得:

请求首行

请求头

请求空行



请求正文:



request的乱码问题:



public static void main(String[] args) throws Exception {
String str = "带门";
byte[] b = str.getBytes("utf-8");//模拟浏览器进行编码
String name = new String(b,"iso-8859-1");//模拟服务器进行解码

//		byte[] by = name.getBytes("iso-8859-1");//反服务器进行编码
//		String str1 = new String(by,"utf-8");
String str1 = new String(name.getBytes("iso-8859-1"),"utf-8");
System.out.println(str1);

}


post请求的乱码解决方案: request.setCharacterEncoding("utf-8");

get请求的乱码解决方案:
String name = request.getParameter("username");//根据用户的name的属性值得到相应的提交信息
String name1 = new String(name.getBytes("iso-8859-1"),"utf8");
System.out.println(name1);


请求转发:

request.getRequestDispatcher("/servlet6").forward(request, response); //地址没变,网页中显示的内容是sevlet6的内容

请求包含:

request.getRequestDispatcher("/servlet6").include(request, response); //地址没变,网页中显示的是原来servlet中的内容和servlet6的内容。

Request域:

request.getAttribute("键");

request.setAttribute("键","值");

request.removeAttribute("键");

request.getAttributeNames();

生命周期:

ServletContext (域) :同生共死

Servlet :声明周期 :不求同生,只求同死。

request:完整的一次请求响应。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: