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:完整的一次请求响应。
相关文章推荐
- ioS学习 UITableViewCell 增加、删除、移动
- Rescue
- 《第一行代码》 随手笔记——第三章 UI开发的点点滴滴
- UITableView介绍 之 复杂cell的高度计算
- 1016-06-首页20-封装工具条---UITableView控件距离顶部的间距问题----cell选中时的背景颜色设置
- jsp request跳转页面和response跳转页面
- 232. Implement Queue using Stacks
- Integer.parseInt(String s) 和 Integer.valueOf(String s) 的区别
- 用UIScrollView,UIPageControl来实现滚动视图。
- iOS完美版的UIScrollView无缝循环:你值得一看
- 从sqlcommandbuilder引出的小想法
- 用UIpickView实现省市的联动
- IOS_压缩图片UIImage
- 用Source Insight追踪Arduino的setup和loop
- 1562 Guess the number
- 625A.Guest From the Past
- 62. 63. Unique Paths 64. Minimum Path Sum
- 设计模式-Builder模式
- JavaSE入门学习29:Java常用类之StringBuffer类和StringBuilder类
- UIImage