LinuxSir.cn,穿越时空的Linuxsir!

 找回密码
 注册
搜索
热搜: shell linux mysql
查看: 875|回复: 4

如何让表单自动提交2次

[复制链接]
发表于 2005-4-21 17:49:19 | 显示全部楼层 |阅读模式
地址是同一个地址,谢谢
发表于 2005-4-21 18:49:48 | 显示全部楼层
form.submit();form.submit();
回复 支持 反对

使用道具 举报

 楼主| 发表于 2005-4-22 09:00:04 | 显示全部楼层

re

这样不行的,问此问题之前我已试了
回复 支持 反对

使用道具 举报

发表于 2005-4-28 12:03:17 | 显示全部楼层
你想做什么 目的是什么 针对同一个地址是不能提交两次的。 那就是两个request了。你把目的说出来看看解决办法
回复 支持 反对

使用道具 举报

 楼主| 发表于 2005-4-28 14:29:48 | 显示全部楼层

re

谢谢你哦,这个问题已经解决了,下面是代码:
[php]
/*
* Created on 2005-4-22
*
* TODO To change the template for this generated file go to
* Window - Preferences - Java - Code Style - Code Templates
*/
package web;

/**
* @author jxd
*
* TODO To change the template for this generated type comment go to
* Window - Preferences - Java - Code Style - Code Templates
*/
//import java.net.*;
import java.io.*;
//import java.util.*;
import HTTPClient.*;
import java.sql.*;

class WebRequester{
          private static InputStream istr = null;
          private static OutputStream ostr = null;
          private static NVPair form_data[];
          private static HTTPConnection httpCon;
          private static HTTPResponse rsp;
          private static String host;
          private static WebRequester instance;
          private WebRequester(){
          }
          public static WebRequester getInstance(){
            if(instance==null){
              instance = new WebRequester();
            }
            return instance;
          }
          public static String request(HTTPConnection connection,String pathName,String method,NVPair form_data[]) {
            try{
               httpCon = connection;
               if(method.toLowerCase().equals("get")){
                 if(form_data!=null)
                   rsp = httpCon.Get(pathName, form_data);
                 else
                   rsp = httpCon.Get(pathName);
               }
              else{
                 if(form_data!=null)
                   rsp = httpCon.Post(pathName, form_data);
                 else
                   rsp = httpCon.Post(pathName);
               }
              istr = rsp.getInputStream();
              BufferedReader reader = new BufferedReader(new InputStreamReader(istr));
              String line;
              StringBuffer result = new StringBuffer();
              while ((line = reader.readLine()) != null) {
                result.append(line + System.getProperty("line.separator"));
              }
              return result.toString();
            } catch(Exception e){
            }
         return "";
          }
        }

public class Flood
{
        Connection con = null;
        ResultSet rs = null;
        FileWriter fw = null;
        BufferedWriter bw = null;
        //Timer timer1;
       
        private HTTPConnection connection;
       
         public Flood()
         {
           getConnection("IP地址",端口号);
           try
           {
                   Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
                  
           }
           catch(Exception err)
           {
                   err.printStackTrace();
           }
         }
          public void releaseConnection()
          {
            if(connection!=null)
            {
              connection.stop();
              connection = null;
            }
          }
          public HTTPClient.HTTPConnection getConnection(String hostName,int port){
             if(connection==null){
               try{
                 connection = new HTTPClient.HTTPConnection(hostName,port);
                 HTTPClient.CookieModule.setCookiePolicyHandler(null);
                 connection.addDefaultModule(Class.forName("HTTPClient.CookieModule"), 1);
                 connection.addModule(Class.forName("HTTPClient.RedirectionModule"),2);
               }catch(Exception e){
                 e.printStackTrace();
               }
             }
             return connection;
          }
         
         /*public void post(String subject,String body){
            NVPair[] form_data = new NVPair[5];
            form_data[0] = new NVPair("forumID","87");
            form_data[1] = new NVPair("subject",subject);
            form_data[2] = new NVPair("classifier","-1");
            form_data[3] = new NVPair("body",body);
            form_data[4] = new NVPair("doPost"," 发 表 ");
         WebRequester.getInstance().request(connection,"post!post.jspa","post",form_data);
         
         }*/
          
         public void reply()
         {
                 NVPair[] form_data = new NVPair[4];
            //提交表单需要多少项,查看回复页面表单可以获得
                 try
                {
                         String mobilecode = "";
                         con = DriverManager.getConnection("jdbcdbc:gxlx","smsuser","smsuser");
                         Statement stmt = con.createStatement();
                         rs = stmt.executeQuery("SELECT  dest,mobilecode,content FROM T_jlds_receive WHERE DeliverId=0");
                         while(rs.next())
                         {
                                         form_data[0] = new NVPair("spnumber",rs.getString("dest"));
                                         form_data[1] = new NVPair("mobile",rs.getString("mobilecode"));
                                         mobilecode = rs.getString("mobilecode");
                                         //form_data[2] = new NVPair("gateway","cm");
                                         //form_data[3] = new NVPair("smallnum","");
                                         form_data[2] = new NVPair("message",rs.getString("content"));
                                         form_data[3] = new NVPair("doPost","submit");
                                         WebRequester.getInstance().request(connection,"gxlx_sms/gxlxmo.jsp","post",form_data);
                                        
                                         System.out.println("发送数据如下");
                                         System.out.println("特服号->"+form_data[0]);
                                         System.out.println("手机号->"+form_data[1]);
                                         System.out.println("内容->"+form_data[2]);
                                         System.out.println("--------------------------");
                                         hasSend(mobilecode);
                                 //}
                         }
            //form_data[5] = new NVPair("threadID",thread);
            //form_data[6] = new NVPair("doPost"," 发 表 ");
                        
                }
                 catch(Exception err)
                {
                         err.printStackTrace();
                }
                 finally
                {
                         if(rs != null)
                         {
                                 try
                                {
                                         rs.close();
                                         System.out.println("已释放记录集...");
                                }
                                 catch(Exception err)
                                {
                                         err.printStackTrace();
                                }
                         }
                         if(con != null)
                         {
                                 try
                                {
                                         con.close();
                                         System.out.println("已沉睡连接...");
                                }
                                 catch(Exception err)
                                {
                                         err.printStackTrace();
                                }
                         }
                }
         }
         
         public void hasSend(String mobilecode)
         {
                 String str = "UPDATE T_jlds_receive SET DeliverID=1 WHERE mobilecode=?";
                 try
                {
                        
                         con = DriverManager.getConnection("jdbcdbc:gxlx","smsuser","smsuser");
                         PreparedStatement pstmt = con.prepareStatement(str);
                         pstmt.setString(1,mobilecode);
                         int flag = pstmt.executeUpdate();
                         if(flag>0)
                         {
                                 System.out.println("手机号"+mobilecode+"已发送");
                                 writeLog(mobilecode,"发送成功");
                         }
                         else
                         {
                                 System.out.println("手机号"+mobilecode+"未发送");
                                 writeLog(mobilecode,"发送失败");
                         }
                }
                 catch(Exception err)
                {
                         err.printStackTrace();
                }
                 finally
                {
                         if(con != null)
                         {
                                 try
                                {
                                         con.close();
                                         System.out.println("已沉睡连接...");
                                }
                                 catch(Exception err)
                                {
                                         err.printStackTrace();
                                }
                         }
                }
         }
         
         public void writeLog(String mobile,String status)
         {
                 String date = new java.util.Date().toString();
                 String message = mobile+"\t"+date+"\t"+status+"\n";
                 try
                {
                         File f = new File("d:\\log\\","log.txt");
                         if(!f.exists())
                         {
                                 System.out.println("正在创建日志文件...");
                                 f.createNewFile();
                                 System.out.println("日志文件创建成功...");
                         }
                         if(f.length()>=100000000)
                         {
                                 System.out.println("日志已满,删除中");
                                 f.delete();
                         }
                         fw = new FileWriter("d:\\log\\log.txt",true);
                         bw = new BufferedWriter(fw,1024);
                         bw.write(message);
                         bw.flush();
                         System.out.println("写入日志成功...");
                }
                 catch(IOException err)
                {
                         err.printStackTrace();
                }
                 finally
                {
                         if(bw != null)
                         {
                                 try
                                {
                                         bw.close();
                                         System.out.println("已释放缓冲流...");
                                }
                                 catch(IOException err)
                                {
                                         err.printStackTrace();
                                }
                         }
                         if(fw != null)
                         {
                                 try
                                {
                                         fw.close();
                                         System.out.println("已释放文件流...");
                                }
                                 catch(IOException err)
                                {
                                         err.printStackTrace();
                                }
                         }
                }
         }
         
         public void diaodu()
         {
                         while(true)
                         {
                                 reply();
                         }
         }
         
         public void finish()
         {
           releaseConnection();
           System.out.println("已经释放资源...");
         }
         
         /*public void run()
         {
                 while(true)
                 {
                         reply();
                         try
                        {
                                 Thread.sleep(3000);
                        }
                         catch(InterruptedException err)
                        {
                                 err.printStackTrace();
                        }
                 }
                
         }*/
          /*public void login(){

            WebRequester wr = WebRequester.getInstance();
            NVPair[] form_data = new NVPair[4];
            //对应登陆需要的表单字段填写
            form_data[0] = new NVPair("formUsername","user");
            form_data[1] = new NVPair("formPassword","pass");
            form_data[2] = new NVPair("formLogins cript","sitename.com/loginuser.jsp");
            form_data[3] = new NVPair("forumLogin","Y");
            //提交到指定登陆页面
            wr.request(connection,"cgi-bin/gzhome/registration/LoginUser1.jsp","post",form_data);
            //假如重定向,必须用该链接再次请求新的页面
            wr.request(connection,"loginuser.jsp","get",null);
            wr.request(connection,"index.jspa","get",null);
          }*/


          public static void main(String[] args)
          {  
                  //Thread thread = new Thread();
                  try
                {
                             Flood f=new Flood();
                             f.diaodu();
                             //thread.start();
             //f.login();
             //post一个新主题,id由系统自己产生
             //f.post("friends","剧本");
             //得到某个主题id,进行指定数量的跟帖
             //for(int i=0;i<5;i++)
             //{
                           /*while(true)
                           {
                                   try
                                {
                                           f.reply();
                                           Thread.sleep(3000);
                                }
                                catch(Exception err)
                                {
                                        err.printStackTrace();
                                }
                           }*/
                             f.finish();
                }
                  catch(Exception err)
                {
                          err.printStackTrace();
                }
                    
               // System.out.println("已发送"+i+"次");
                
             //}
           /*如下是读取某个文件每一行文字作为回帖进行灌水
           BufferedReader br = new BufferedReader(new FileReader("E:\\movie\\101-105\\Friends - 1x04 - TOW George Stephanopoulos.CHN.srt"));
           StringBuffer sb = new StringBuffer();
           String t = null;
           int counter=0;
           while((t=br.readLine())!=null){
            if(t.length()==0){
              //System.out.println(sb.toString());
                 //System.out.println("====");
             counter++;
             f.reply("66617","" + counter,sb.toString());
             sb.delete(0,sb.length());
            }
            sb.append(t + "\n");
          
           }*/
          
          
          
          }
}

[/php]

刚开始范傻,想在页面上解决,后来想想http协议的底层就是socket连接,所以就这样写了
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则

快速回复 返回顶部 返回列表