| 网站首页 | 业界新闻 | 群组 | 交易 | 人才 | 下载频道 | 博客 | 代码贴 | 编程论坛
共有 324 人关注过本帖
标题:验证码出错
只看楼主 加入收藏
zcdjt
Rank: 3Rank: 3
等 级:论坛游侠
威 望:4
帖 子:93
专家分:181
注 册:2014-9-9
结帖率:85.71%
  问题点数:0  回复次数:0   
验证码出错
//我参考的这个程序,验证码图片运行时出不来,点击“看不清”刷新的是用户的姓名和密码,并没有刷新验证码,并且姓名和密码为什么会自动填写,各位大神能给一些帮助吗?谢谢!
<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<html>
<script type="text/javascript">
    function toreal() {
        document.location.href = "index.jsp";
    }
</script>
<body>
    <table>
        <form action="" method="post">
            <b>请输入姓名: <input type="text" name="userName"></b><br> <b>请输入密码:<input
                type="password" name="userPassWord"></b><br> <b>验证码: <input
                type="text" name="code"> <img alt="验证码"
                src="/code/user_code/Code"> <a href="javascript:toreal()">看不清</a></b><br>
            <input type="submit" value="登录">

        </form>
    </table>
</body>
</html>

public class Code extends HttpServlet {
    public void doGet(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
        // 通知浏览器不要缓存
        response.setHeader("Expires", "-1");
        response.setHeader("Cache-Control", "no-cache");
        response.setHeader("Pragma", "-1");

        int width = 25, height = 120;
        // 得到一个内存图像BufferedImage
        BufferedImage image = new BufferedImage(width, height,
                BufferedImage.TYPE_INT_RGB);
        // 得到一个画笔
        Graphics g = image.getGraphics();
        // 画边框drawRect绘制指定矩形的边框。
        g.drawLine(0, 0, width, height);
        // 填充颜色
        g.setColor(Color.blue);
        g.fillRect(1, 1, width - 2, height - 2);
        // 画干扰线
        g.setColor(Color.BLACK);
        Random rnd = new Random();
        for (int i = 100; i >= 0; i--) {
            g.drawLine(rnd.nextInt(width), rnd.nextInt(height),
                    rnd.nextInt(width), rnd.nextInt(height));
        }
        // 生成随机数字
        g.setColor(Color.green);
        g.setFont(new Font("微软雅黑", Font.BOLD | Font.ITALIC, 20));// BOLD加粗,ITALIC斜体
        int d = 15;
        for (int j = 0; j < 4; j++) {
            g.drawString(rnd.nextInt(10) + "", d, 20);
            d += 20;
        }
        // 输出到web页面
        ImageIO.write(image, "jpg", response.getOutputStream());
    }

    public void doPost(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
        doGet(request, response);
    }

}


2017-02-28 09:47







关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.026544 second(s), 9 queries.
Copyright©2004-2018, BCCN.NET, All Rights Reserved