新手上路,用SSM框架最近做了个网站,注册页面用localhost访问时就正常,但是用ip地址访问时验证码的请求能访问到,但是生成验证码的方法就访问不到.
这是ip访问的打桩结果
image1
IMAGE2
/user/createImg.do //生成验证码的请求
/user/check.do  
imgcode:null //生成验证码
yzm:0844 //输入的验证码
/user/register.do //注册请求这是localhost访问的结果,正常
image1
IMAGE2
/user/createImg.do
/user/check.do
imgcode:J7OM
yzm:J7OM
/user/register.do搞不懂是什么原因啊

解决方案 »

  1.   

    public final class ImageUtil {

    // ��֤���ַ���
    private static final char[] chars = { 
    '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 
    'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 
    'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z'};
    // �ַ�����
    private static final int SIZE = 4;
    // ����������
    private static final int LINES = 5;
    // ���
    private static final int WIDTH = 80;
    // �߶�
    private static final int HEIGHT = 40;
    // �����С
    private static final int FONT_SIZE = 30; /**
     * ���������֤�뼰ͼƬ
     */
    public static Object[] createImage() {
    StringBuffer sb = new StringBuffer();
    // 1.�����հ�ͼƬ
    BufferedImage image = new BufferedImage(
    WIDTH, HEIGHT, BufferedImage.TYPE_INT_RGB);
    // 2.��ȡͼƬ����
    Graphics graphic = image.getGraphics();
    // 3.���û�����ɫ
    graphic.setColor(Color.LIGHT_GRAY);
    // 4.���ƾ��α���
    graphic.fillRect(0, 0, WIDTH, HEIGHT);
    // 5.������ַ�
    Random ran = new Random();
    for (int i = 0; i <SIZE; i++) {
    // ȡ����ַ�����
    int n = ran.nextInt(chars.length);
    // ���������ɫ
    graphic.setColor(getRandomColor());
    // ���������С
    graphic.setFont(new Font(
    null, Font.BOLD + Font.ITALIC, FONT_SIZE));
    // ���ַ�
    graphic.drawString(
    chars[n] + "", i * WIDTH / SIZE, HEIGHT / 2);
    // ��¼�ַ�
    sb.append(chars[n]);
    }
    // 6.��������
    for (int i = 0; i < LINES; i++) {
    // ���������ɫ
    graphic.setColor(getRandomColor());
    // �������
    graphic.drawLine(ran.nextInt(WIDTH), ran.nextInt(HEIGHT),
    ran.nextInt(WIDTH), ran.nextInt(HEIGHT));
    }
    // 7.������֤���ͼƬ
    return new Object[]{sb.toString(), image};
    } /**
     * ���ȡɫ
     */
    public static Color getRandomColor() {
    Random ran = new Random();
    Color color = new Color(ran.nextInt(256), 
    ran.nextInt(256), ran.nextInt(256));
    return color;
    }

    public static void main(String[] args) throws IOException {
    System.out.println(1111);
    Object[] objs = createImage();
    BufferedImage image = 
    (BufferedImage) objs[1];
    // /home/soft01/1.png
    OutputStream os = 
    new FileOutputStream("d:/1.png");
    ImageIO.write(image, "png", os);
    os.close();
    }
    这是验证码的代码,用ip访问时 在D盘找不到生成的验证码图片