java模拟登录代码 java爬虫模拟登录

请问用java程序模拟qq登录界面的代码怎么写啊?

太简单了!你看看! package dyno.swing.beans.qq; import javax.swing.*; import javax.swing.event.MouseInputListener; import org.jvnet.substance.skin.SubstanceOfficeBlue2007LookAndFeel; /*import org.jvnet.substance.skin.SubstanceModerateLookAndFeel; import org.jvnet.substance.skin.SubstanceOfficeBlue2007LookAndFeel;*/ import java.awt.*; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.awt.event.MouseEvent; import java.io.IOException; import java.io.PrintWriter; import java.net.Socket; import java.net.UnknownHostException; import java.sql.ResultSet; import java.sql.SQLException; import java.util.Scanner; public class QQLogin extends JFrame implements MouseInputListener,ActionListener{ JLabel guanggao,beijing,wenzi,shezhi,zhanghaowb,qq1,dengluzhuangtai; // JTextField zhanghao; JPopupMenu haoma; JComboBox zhanghao; JPasswordField mima; JCheckBox jizhumima,zidongdenglu; JButton denglu,chashamuma; JProgressBar jpb; SimThread activity; Timer activityMonitor; String name,qq; Socket s; public QQLogin() { try { UIManager.setLookAndFeel("com.sun.java.swing.plaf.windows.WindowsLookAndFeel"); } catch (ClassNotFoundException e1) { // TODO 自动生成 catch 块 e1.printStackTrace(); } catch (InstantiationException e1) { // TODO 自动生成 catch 块 e1.printStackTrace(); } catch (IllegalAccessException e1) { // TODO 自动生成 catch 块 e1.printStackTrace(); } catch (UnsupportedLookAndFeelException e1) { // TODO 自动生成 catch 块 e1.printStackTrace(); } chashamuma = new JButton("查杀木马"); chashamuma.setBounds(240, 155,85, 20); this.add(chashamuma); jpb = new JProgressBar(); jpb.setStringPainted(true); jpb.setBounds(100, 240, 200, 15); this.add(jpb); chashamuma.addActionListener(new ActionListener(){ public void actionPerformed(ActionEvent e){ jpb.setMaximum(1000);//设置进度栏的最大值 activity=new SimThread(1000); activity.start();//启动线程 activityMonitor.start();//启动定时器 chashamuma.setEnabled(false);//禁止按钮 } }); activityMonitor=new Timer(100,new ActionListener(){//每0.5秒执行一次 public void actionPerformed(ActionEvent e){//以下动作将在事件调度线程中运行,十分安全 int current=activity.getCurrent();//得到线程的当前进度 jpb.setValue(current);//更新进度栏的值 if(current==activity.getTarget()){//如果到达目标值 activityMonitor.stop();//终止定时器 chashamuma.setEnabled(true);//激活按钮 } } }); dengluzhuangtai = new JLabel(new ImageIcon("zaixianzhuangtai.jpg")); dengluzhuangtai.setBounds(75, 145, 35, 30); this.add(dengluzhuangtai); dengluzhuangtai.addMouseListener(this); denglu = new JButton("登录"); denglu.setBounds(140, 155, 80, 20); this.add(denglu); this.setAlwaysOnTop(true); zidongdenglu = new JCheckBox("自动登录"); zidongdenglu.setBounds(200, 190, 100, 30); this.add(zidongdenglu); jizhumima = new JCheckBox("记住密码"); jizhumima.setBounds(100, 190, 100, 30); // jizhumima.setBackground(new Color(228, 244, 255)); this.add(jizhumima); haoma = new JPopupMenu(); /* zhanghao = new JTextField(20); zhanghao.setBounds(120, 78, 135, 20); zhanghao.setBorder(BorderFactory.createMatteBorder(1, 1, 1, 1, Color.WHITE)); zhanghao.setFont(new Font("宋体",Font.PLAIN,13)); this.add(zhanghao);*/ // zhanghaowb = new JLabel(new ImageIcon("2.png")); // zhanghaowb.setBounds(90, 73, 194, 31); // jiantou = new JLabel(new ImageIcon("baijiantou.png")); // jiantou.setBounds(256, 78, 23, 21); // jiantou.addMouseListener(this); // this.add(jiantou); // this.add(zhanghaowb); chashamuma.addActionListener(this); mima = new JPasswordField(); mima.setEchoChar('*'); mima.setFont(new Font("宋体",Font.PLAIN,13)); mima.setBounds(100, 113, 150, 20); this.add(mima); zhanghao = new JComboBox(); zhanghao.setEditable(true); zhanghao.setBounds(100, 78, 150, 20); zhanghao.setFont(new Font("宋体",Font.PLAIN,13)); this.add(zhanghao); guanggao = new JLabel(new ImageIcon("guanggao.gif")); guanggao.setBounds(0, 0, 334, 64); beijing = new JLabel(new ImageIcon("beijing.jpg")); beijing.setBounds(0, 64, 334, 154); wenzi = new JLabel(new ImageIcon("wenzi.jpg")); wenzi.setBounds(30, 75, 50, 100); denglu.addActionListener(this); // zhanghaowb.addMouseListener(this); // zhanghao.addMouseListener(this); this.add(wenzi); this.add(beijing); this.setLayout(null); this.add(guanggao); this.setVisible(true); this.setDefaultCloseOperation(3); this.setSize(340, 250); this.setLocationRelativeTo(null); } public static void main(String[] args) { /*JFrame.setDefaultLookAndFeelDecorated(true); try { UIManager.setLookAndFeel(new SubstanceOfficeBlue2007LookAndFeel()) ; UIManager.setLookAndFeel("org.jvnet.substance.skin.SubstanceOfficeBlue2007LookAndFeel"); } catch (Exception e) { System.out.println("Substance Raven Graphite failed to initialize"); } SwingUtilities.invokeLater(new Runnable() { public void run() { QQLogin w = new QQLogin(); w.setVisible(true); } });*/ new QQLogin(); } public void mouseClicked(MouseEvent e) { // TODO 自动生成方法存根 } public void mouseEntered(MouseEvent e) { if(e.getSource() == dengluzhuangtai) { dengluzhuangtai.setIcon(new ImageIcon("zaixianzhuangtaidian.jpg")); } } public void mouseExited(MouseEvent e) { if(e.getSource() == dengluzhuangtai) { dengluzhuangtai.setIcon(new ImageIcon("zaixianzhuangtai.jpg")); } } public void mousePressed(MouseEvent e) { // TODO 自动生成方法存根 } public void mouseReleased(MouseEvent e) { // TODO 自动生成方法存根 } public void mouseDragged(MouseEvent e) { // TODO 自动生成方法存根 } public void mouseMoved(MouseEvent e) { // TODO 自动生成方法存根 } public class liaotianchuangkou { } class SimThread extends Thread{//线程类 private int current;//进度栏的当前值 private int target;//进度栏的最大值 public SimThread(int t){ current=0; target=t; } public int getTarget(){ return target; } public int getCurrent(){ return current; } public void run(){//线程体 try{ while (currenttarget !interrupted()){//如果进度栏的当前值小于目标值并且线程没有被中断 sleep(10); current++; if(current == 700) { sleep(3000); } else if(current == 730) { sleep(1000); } } }catch (InterruptedException e){} } } public void actionPerformed(ActionEvent e) { if(e.getSource() == chashamuma) { this.setBounds(300, 300, 340, 300); } else if(e.getSource() == denglu) { String zh = (String) zhanghao.getSelectedItem(); System.out.println(zhanghao.getSelectedItem()); // System.out.println(zhanghao.getItemAt(0)); char [] str = mima.getPassword(); String mima = String.valueOf(str);; System.out.println(mima); // Sql login = new Sql(); // if(login.login(zh,mima)) // { try { s = new Socket("127.0.0.1",8888); System.out.println(s); PrintWriter pw; Scanner sc; pw = new PrintWriter(s.getOutputStream(),true); sc = new Scanner(s.getInputStream()); String str2 = "login#289872400198724#"+zh+"#289872400198724#"+mima; System.out.println(str2); pw.println(str2); String str3 = sc.nextLine(); String yanzheng[] = str3.split("#"); System.out.println(str3); if(yanzheng[0].equals("true")) { System.out.println("登陆成功!"); name = yanzheng[1]; qq = yanzheng[2]; // this.setVisible(false); // Thread.sleep(5000); System.out.println("woao"+name); System.out.println("woai"+qq); Logined logined = new Logined(name,qq); this.setVisible(false); } else { JOptionPane.showMessageDialog(this, "用户名或密码错误!", "用户名或密码错误!", 0); } } catch (UnknownHostException e2) { // TODO 自动生成 catch 块 e2.printStackTrace(); } catch (IOException e2) { // TODO 自动生成 catch 块 e2.printStackTrace(); } /*try { login.rs = login.stat.executeQuery("select * from qquser where username='"+zh+"' and password = '"+mima+"'"); boolean flag = login.rs.next(); if(flag == true) { name = login.rs.getString("name"); qq = login.rs.getString("username"); } else { }*/ // } catch (SQLException e1) { // TODO 自动生成 catch 块 // e1.printStackTrace(); // } } else { JOptionPane.showMessageDialog(this, "用户名或密码错误", "输入错误", 0); } // this.setVisible(false); //new Logined(); } }

创新互联网站建设公司,提供网站建设、网站设计,网页设计,建网站,PHP网站建设等专业做网站服务;可快速的进行网站开发网页制作和功能扩展;专业做搜索引擎喜爱的网站,是专业的做网站团队,希望更多企业前来合作!

用java程序实现自动登录

之前,也考虑过使用单点登录,几经尝试之后还是放弃了。

我习惯使用Java,本能地开始寻找Java的解决方法,在Google中输入"Java自动登录"、"Java网页模拟登录"、"JavaPost登录",结果倒是不少,内容也差不多,我尝试很多次终究也没有达到我预期的目标。后来,我都不知道这些代码应该在jsp页面中执行还是在c/s结构的程序中执行。但这些代码确实管用。 我们先分析一下代码: URLurl=newURL(surl); URLConnectionconn=url.openConnection(); conn.setDoOutput(true); OutputStreamWriterout=newOutputStreamWriter(conn.getOutputStream()); Stringstr="username=yournamepassword=123456"; out.write(str); out.flush(); out.close(); 到这里,如果在C/S结构中,且参数正确,程序能够成功登录到这个oa系统,要看到结果,你可以通过下面的代码将系统服务器返回的结果System.out.println()出来。 Stringsling=""; Stringscontent=""; BufferedReaderin=newBufferedReader(newInputStreamReader(conn.getInputStream(),"UTF-8")); while((sling=in.readLine())!=null) scontent+=in+"\r\n"; System.out.println(scontent); 在C/S结构下,可以到得到控制台输出了返回值,从返回内容里可以看出程序已经成功登录,但要是把这个网址浏览器打开,还是得重新登录,问题没有得到根本解决。如果只是恶意注册,到这里应该就达到目的了。 看样子C/S结构下不容易实现网页程序自动登录,除非你在C/S程序中内嵌一个浏览器,直接在这个浏览器中自动访问系统,应该没有别的方法,主要问题在于我们没有办法共享Session. 为了便于共享Session,我们只能在浏览器中实现网页自动登录,通过上面的代码在jsp页面中测试,达不到预期目标。 网页自动登录,就是希望程序自动填充用户名和密码,然后以Post方式提交给登录页面的Form所指向的action页面或方法。我将系统的登录页面的源代码保存成一个网页,然后在username和password文本框中设置默认值,然后通过这网页登录系统,测试后,发现可行。接下来,你可能已经想到了解决方法。 我们可以通过url.openConnection()建立连接,将返回的scontent打印出来,然后接着打印以下代码: out.println("\r\n"); out.println("document.getElementsByName(\"username\")[0].value=yourname;\r\n"); out.println("document.getElementsByName(\"password\")[0].value=123456;\r\n"); out.println("document.forms[0].submit();\r\n"); out.println("\r\n"); 原理很简单,通过login.jsp将登录页面的全部源代码写在当前页面,然后使用javascript脚本将用户名和密码的值填充上,最后提交表单。这样中,终于实现了自动登录的目标。现在我通过一个特殊的网址,就可以自动访问这个oa了。 你可能注意到参数url,他的值是经过加密的,内容是用户名和密码。当然,你也可以加上有效期,即在有效期内这个链接才是有效的,才可以实现自动登录。

希望能解决您的问题。

模拟一个简单的用户登陆程序,判断登录的用户名和密码是否正确,输出登录判断结果,用java怎么写?

package test;\x0d\x0aimport java.util.Scanner;\x0d\x0apublic class TestLogin {\x0d\x0aprivate static final String USERNAME = "Tom";//此处定义用户名\x0d\x0aprivate static final String PASSWORD = "123";//定义密码\x0d\x0apublic static void main(String[] args) {\x0d\x0aScanner sc = new Scanner(System.in);\x0d\x0aSystem.out.print("请输入您的用户名:");\x0d\x0aString username_in = sc.next();\x0d\x0aSystem.out.print("请输入您的密码:");\x0d\x0aString password_in = sc.next();\x0d\x0aif(username_in.equals(USERNAME) password_in.equals(PASSWORD)){\x0d\x0aSystem.out.println("登录成功");\x0d\x0a}else{\x0d\x0aSystem.out.println("用户名或密码错误");\x0d\x0a}\x0d\x0a}\x0d\x0a} \x0d\x0a这是从控制台输入的最简单的方法。

java编写一个程序模拟用户登录操作,用户名和密码从键盘输入?

import java.util.Scanner;

public class LoginTest {

/**

* @param args

*/

public static void main(String[] args) {

String loginName = "admin";

String passWord = "123456";

Scanner sc = new Scanner(System.in);

boolean isSuccess = false;

int index = 0;

while(!isSuccess){

System.out.println("请输入用户名:");

String name = sc.nextLine(); //读取字符串型输入

System.out.println("请输入密码:");

String passW = sc.nextLine();

if(loginName.equals(name)passWord.equals(passW)){

System.out.println("户名密码正确,退出程序");

isSuccess = true;

}else{

if(++index=3){

System.out.println("用户名密码错误,程序即将退出");

return;

}else{

System.out.println("用户名密码错误,请重新输入");

}

}

}

}

}

JAVA超简单的模拟登陆

public static void main(String[] args){

int i=0;

for(;i3;i++){

Scanner scan=new Scanner(System.in);

System.out.println("请输入用户名:");

String Cuser=scan.nextLine();

System.out.println("请输入密码:");

String Cpwd=scan.nextLine();

if(!Cuser.equals("abc")){

if(i+1==3)

System.out.println("失败3次");

else

System.out.println("用户名非法!【第"+(i+1)+"次登录】");

}

else if(!Cpwd.equals("abc")){

if(i+1==3)

System.out.println("失败3次");

else

System.out.println("登录密码错误!【第"+(i+1)+"次登录】");

}

else

{

System.out.println("恭喜您,登录信息通过验证!");

}

}

}


文章名称:java模拟登录代码 java爬虫模拟登录
分享地址:http://scyanting.com/article/hhoids.html