日期:2014-05-18  浏览次数:20782 次

如何用JAVA程序读取网页的验证码
网页中的登陆或填写表单是要填写图片类的严整码,
如何使用程序自动读取出来
请高手指教!!!
最好有源代码~
谢谢

------解决方案--------------------
你可以加入我的群28393917
群共享里有个登录模块,是我做的,你可以看看,你的问题就能解决了

------解决方案--------------------
楼主是想做OCR一类的自动识别吧?

如果能自动识别就不叫验证码的
不过一些简单格式的除外:)
------解决方案--------------------
package so.gd.cn.imgmask;

import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.awt.*;
import java.awt.image.*;
import java.util.*;
import javax.imageio.*;


public class ImageServlet extends HttpServlet {

/**
* Constructor of the object.
*/
public ImageServlet() {
super();
}

/**
* Destruction of the servlet. <br>
*/
public void destroy() {
super.destroy(); // Just puts "destroy " string in log
// Put your code here
}

/**
* The doGet method of the servlet. <br>
*
* This method is called when a form has its tag value method equals to get.
*
* @param request the request send by the client to the server
* @param response the response send by the server to the client
* @throws ServletException if an error occurred
* @throws IOException if an error occurred
*/
public void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {

doPost(request,response);
}

/**
* The doPost method of the servlet. <br>
*
* This method is called when a form has its tag value method equals to post.
*
* @param request the request send by the client to the server
* @param response the response send by the server to the client
* @throws ServletException if an error occurred
* @throws IOException if an error occurred
*/
public void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {

response.setHeader( "Pragma ", "No-cache ");
response.setHeader( "Cache-Control ", "no-cache ");
response.setDateHeader( "Expires ", 0);


int width=60, height=18;
BufferedImage image = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB);


Graphics g = image.getGraphics();


Random random = new Random();


g.setColor(getRandColor(200,250));
g.fillRect(0, 0, width, height);


g.setFont(new Font( "Times New Roman ",Font.PLAIN,18));

// g.setColor(new Color());
// g.drawRect(0,0,width-1,height-1);


g.setColor(getRandColor(160,200));
for (int i=0;i <155;i++)
{
int x = random.nextInt(width);
int y = random.nextInt(height);
int xl = random.nextInt(12);
int yl = random.nextInt(12);