response
1.response的中文处理、解决乱码问题;
//使用字符流
//设置浏览器默认编码utf8
response.setHeader("content-type", "text/html;charset=utf-8");
//设置response默认编码
response.setCharacterEncoding("utf-8");
//字符流输出中文
response.getWriter().print("文本");
//使用字节流
//浏览器默认编码
response.setHeader("content-type", "text/html;charset=utf-8");
//response响应编码
response.getOutputStream().write("中文".getBytes("utf-8"));
2.response生成验证码
//1,生成内存中的图片
int width = 150;
int height = 30;
BufferedImage bufferedimage = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB);
Graphics2D gp = (Graphics2D) bufferedimage.getGraphics();
gp.setColor(Color.WHITE);
gp.fillRect(0, 0, width, height);
gp.setColor(Color.BLACK);
gp.drawRect(0, 0, width-1, height-1);