部分文章内容为公开资料查询整理,原文出处可能未标注,如有侵权,请联系我,谢谢。邮箱地址:gnivor@163.com ►►►需要气球么?请点击我吧!

JavaWeb学习笔记--HttpServletRequest、HttpServletResponse对象常用方法

HttpServletRequest

HttpSession session = request.getSession(true);    //获取会话对象

Cookie[] cookies = request.getCookies();  //获取请求相关的Cookie

 

HttpServletResponse

response.setContentType("text/html;charset=GB2312");  //设置页面格式

response.setContentType("application/pdf");        //设置页面格式为PDF

response.setContentType("application/msword");      //Servlet打开一个word文档

response.setContentType("application/vnd.ms-excel");      //Servlet打开一个excel表

response.setCharacterEncoding("gb2312");  //确保参数信息以汉字编码方式提取

PrintWriter out = response.getWriter();  //获取页面的输出流

 

//字符串作为URL格式编码,其中的某些字符将被十六进制的转义序列进行替换

String encodedUrl = response.encodeURL(contextPath+"/servlet/URLRewriteServer?name=张三&age=27");  



 

 

 

posted @ 2015-01-19 16:11  流了个火  阅读(331)  评论(0编辑  收藏  举报
►►►需要气球么?请点击我吧!►►►
View My Stats