摘要: 1 //登录成功自动跳转2 //response码表3 resp.setCharacterEncoding("utf-8");4 resp.setHeader("refresh", "3;url='/day03/index.jsp'");5 //设置浏览器码表6 resp.setContentType("text/html;charset=utf-8");7 resp.getWriter().write("登录成功,自动3秒后跳转,如果没跳转,请点击跳转"); 这里用到了resp 阅读全文
posted @ 2013-12-25 17:27 哎呦喂,我的小祖宗╰つ 阅读(438) 评论(0) 推荐(0) 编辑
摘要: servlet 1 public class ServletDemo2 extends HttpServlet { 2 3 private static final int WIDTH = 150; 4 private static final int HEIGHT = 30; 5 6 public void doGet(HttpServletRequest request, HttpServletResponse response) 7 throws ServletException, IOException { 8 ... 阅读全文
posted @ 2013-12-25 17:18 哎呦喂,我的小祖宗╰つ 阅读(295) 评论(0) 推荐(0) 编辑
摘要: 通过response响应头content-disposition,来下载文件,如果文件有中文,就用url编码 1 String path = this.getServletContext().getRealPath("/download/妞儿.jpg"); 2 String fileName = path.substring(path.lastIndexOf("\\") + 1); 3 //如果fileName是中文名字,那么我就要用URL编码 URLEncoder.encode(s, enc); 4 response.set... 阅读全文
posted @ 2013-12-25 13:50 哎呦喂,我的小祖宗╰つ 阅读(216) 评论(0) 推荐(0) 编辑
摘要: 在servlet中,通过response向浏览器写中文,会出现乱码,那么response向浏览器写数据一共有两种方式 1.getOutputStream.write();字节流 2.PrintWriter.write();字符流 我们都知道,字节流可以读写任何的数据,而字符流只能读写字符数据。 这里是怎么把我们servlet的数据写到浏览器的,要说一下,这里是我们把数据先写进response里面,然后服务器看到response里面有数据,那么这时服务器才写给浏览器,才会显示我们要写入的数据。简单的画张图。 首先说第一种写入getOutputStream.write();字... 阅读全文
posted @ 2013-12-25 11:47 哎呦喂,我的小祖宗╰つ 阅读(508) 评论(0) 推荐(0) 编辑