java验证码及其刷新
1.servlet产生验证码:
package com.servlet;
import java.awt.Color;
import java.awt.Font;
import java.awt.Graphics;
import java.awt.image.BufferedImage;
import java.io.IOException;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.util.Random;
import javax.imageio.ImageIO;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
public class Img extends HttpServlet {
public void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
response.setContentType("image/jpeg");
response.setHeader("Pragma","No-cache");
response.setHeader("Cache-Control","no-cache");
response.setDateHeader("Expires",0);
OutputStream out=response.getOutputStream();
int w=80,h=20;
BufferedImage img=new BufferedImage(w,h,BufferedImage.TYPE_INT_RGB);
Graphics g=img.getGraphics();
Random ran=new Random();
g.fillRect(0, 0, w, h);
g.setFont(new Font("Times New Roman",Font.ITALIC,18));
String sRan="";
for(int i=0;i<4;i++){
String rand=String.valueOf(ran.nextInt(10));
sRan+=rand;
g.setColor(new Color(20+ran.nextInt(110),20+ran.nextInt(110),20+ran.nextInt(110)));
g.drawString(rand,20*i+6,16);
}
request.getSession().setAttribute("ch", sRan);
g.dispose();
ImageIO.write(img, "jpeg", out);
}
public void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
doGet(request, response);
}
}
2.嵌入html中
<img src="Img" >
3.验证码的刷新
1)点击验证码刷新
<img
相关文档:
集合模式:
作用:处理由一些对象组成的组或者集合;处理如何组织类和对象来形成更大结构的细节;关注设计一个无冗余数据类的最有效方法;允许在一组对象构成的集合上定义操作。
1. 合成:允许单个对象合成对象以一种统一的方式被访问。换句话说,合 ......
/**
* 处理时间异常 Date to String
* 如果转换出现异常会给默认值00:00
* @param time
* @param sdf
* @return
*/
public static String handleDateParseException(Object time){
String tempTime = "00:00";
try{
......
报文鉴别在身份认证中占重要位置,是认证系统的一个重要环节,在金融和商业系统中广泛应用。
报文鉴别常用报文鉴别码(Message Authentication Code,即MAC)作为鉴别的基础,
......
Java传递参数有两种 :值传递,引用传递
一般引用类型 是引用传递,值类型是值传递
值类型是原始数据类型 包括 int,byte,char short long,boolean,float,double
引用类型就是一般的class类 当然也包括原始数据的封装类型 比如int的
封装类型为Integer
一般情况下:
值传递:
例子 1 public void show1(int str ......