How to send two request in the same connection with HttpURLConnection?

As the title, I want to send two or more requests in the same connection with HttpsURLConnection..I wish all requests are in the same session.
My code is as following:
package test1;
//import javax.net.ssl.*;
import java.net.*;
import java.io.*;
public class httptest {
public httptest() {
public void test() {
HttpURLConnection uc = null;
String urlStr="";
urlStr="http://172.16.245.151/test/page1.jsp";
try {
URL u = new URL(urlStr);
uc = (HttpURLConnection) u.openConnection();
uc.setRequestMethod("GET");
uc.setDoOutput(true);
// uc.connect();
OutputStream out = uc.getOutputStream();
out.flush();
out.close();
catch (Exception ex) {
System.out.println(ex.getMessage());
public static void main(String[] args) {
httptest tt = new httptest();
tt.test();
The sample class just can send a request..Now we think of the sentence :uc = (HttpURLConnection) u.openConnection();
Obviousely, a HttpURLConnection can just have a Object of the Class URL, and the Class URL have no setURL mothed. So I can't use a HttpURLConnection to send two request.
I just want the HttpURLConnect is the same to IE...Do you understand what I mean?
Any helps will be appreciated...

As the title, I want to send two or more requests in the same connection with HttpsURLConnection..I wish all requests are in the same session.
My code is as following:
package test1;
//import javax.net.ssl.*;
import java.net.*;
import java.io.*;
public class httptest {
public httptest() {
public void test() {
HttpURLConnection uc = null;
String urlStr="";
urlStr="http://172.16.245.151/test/page1.jsp";
try {
URL u = new URL(urlStr);
uc = (HttpURLConnection) u.openConnection();
uc.setRequestMethod("GET");
uc.setDoOutput(true);
// uc.connect();
OutputStream out = uc.getOutputStream();
out.flush();
out.close();
catch (Exception ex) {
System.out.println(ex.getMessage());
public static void main(String[] args) {
httptest tt = new httptest();
tt.test();
The sample class just can send a request..Now we think of the sentence :uc = (HttpURLConnection) u.openConnection();
Obviousely, a HttpURLConnection can just have a Object of the Class URL, and the Class URL have no setURL mothed. So I can't use a HttpURLConnection to send two request.
I just want the HttpURLConnect is the same to IE...Do you understand what I mean?
Any helps will be appreciated...

Similar Messages

  • How to run two query  in the same preparedStatement

    Hi all,
    Please tell me how to run two queries in the same preparedStatement object ?
    In my module I have to run two queries and I don't want to make two methods for running two different queries.
    I just want to call this method for both of my queries.
    methodName(long param)
    Connection conn=null;
    PreparedStatement pstmt=null;
    //////////////// some coding
    Please Help !
    Thanks in advance
    amitindia

        public void foo()
            Connection connection = null;
            PreparedStatement stmt = null;
            try {
                connection = ...get from pool...;
                stmt = connection.prepareStatement("...");
                ...fetch results...;
                stmt.close();
                stmt = null; // So the finally statement works if there is an exception
                stmt = connection.prepareStatement("...");
                ...fetch results...;
            } finally {
                if (stmt != null) ..close it...;
                if (connection != null) ..return it to pool...;
        }

  • How to get two parameters in the same line of selection screen?

    hello
    i need to get my selection csreen like bellow.
    r1 radiobuttion  -some space --p1 parameter
    i should not get the parameter in the next line of  radiobuttion.
    how to get two parameters in the same line of selection screen?

    hi....
    modify the following code
    it will work
    SELECTION-SCREEN BEGIN OF BLOCK SL1 WITH FRAME TITLE TEXT-003.
    SELECTION-SCREEN BEGIN OF LINE.
    SELECTION-SCREEN COMMENT 10(15) TEXT-001
                     FOR FIELD P1.
    SELECTION-SCREEN POSITION POS_LOW.
    PARAMETERS : P1 TYPE   C USER-COMMAND R2 RADIOBUTTON GROUP R2 DEFAULT 'X',
      P2 TYPE SCARR-CARRNAME,
      P3 TYPE CHAR1 RADIOBUTTON GROUP R2.
    SELECTION-SCREEN END OF LINE.
    SELECTION-SCREEN END OF BLOCK SL1.

  • HOW TO PUT TWO PANNEL IN THE SAME PAGE

    HI ALL
    I NEED TO KNOW HOW TO PUT TWO PANNEL IN THE SAME PAGE TO FULLY UTILIZE FULL PAGE AREA BECAUSE THE PANNEL WIDTH IS TOO SMALL , SO I WANT TO MAKE THE PAPER CONTAIN TO PANNELS VERTICALLY.
    THANK YOU

    So Barb,
    I like to use multiple desktops and move back and forth between then using gestures. At the moment I have 5 open: Chrome, Firefox, Safari, Photoshop CS 6 and a desktop. I use "gestures" to navigate between them:
    Mac Basics: Multi-Touch gestures - Apple Support
    and I use Mission Control (F3) to move the various desktops around in the order I want them.
    Mac Basics: Mission Control - Apple Support
    So say I'm searching for a photo to open in CS 6, I find it on the open desktop then hit select "open" in CS 6 and go to that folder in the select pane.
    Even right now I'm typing this in Safari and "gesturing" back to Chrome where I did the search about multi touch and mission control. I drag copy the URL there  and gestured back here to paste the URL into this text.
    If you did a lot of photo searches, I set professional clients of mine in Chicago up with dual monitors (In this case you'd have an external monitor on extended desktop.). So all you need to do is just glance over at the second monitor slide your cursor over there open stuff up find your photo and go back to Photoshop and open it up.
    Hope this helps.

  • How to write two item in the same line?

    In the smartforms,how to write two item in the same line?
    eg
    1   *************                                    2  *****************
    3  **************                                   4  ******************
    5  ***************
    Anyone got any idea to do this.
    Thanks in advance

    Hi,
    In the smartform the main windows is 20cm.I use the table output my data.Because the output is two item in same line,I define two rows in the table line type.
    Question:
    Should I define the table width 20cm?
    In the main area of table , should I define two folders and each of folder include a line? The second item I had already defined as Append Directly,but the item 1 and item 2 don't in the same line.
    Regards

  • How to insert  two queries in the same workbook in new BI 7.0 Bex web analy

    Hi
    Can you please advise how to insert multiple queries in the same workbook in BI 7.0 web analyser.
    Sarah

    Hi,
    You need to switch to design mode (BEx Analyser Menu - Design Toolbar - Design Mode). For each query that you want to embed, insert an analysis grid item in the workbook. Link each analysis grid to its corresponding data provider (query).
    Hope this helps.
    Regards,
    Rajkandula

  • Can two people use the same computer with two different ipods?

    I was just wondering if me and my mother can use the same computer with our ipods?

    Glad you asked. Before you get rid of the old one move its iTunes Library to the new one:
    iTunes: How to move your music to a new computer
    http://support.apple.com/kb/HT4527
    "Deauthorize" the old computer too. Go to the iTunes Store menu and select "Deauthorize This Computer..."
    I hope you get a Mac this time

  • How to get a file in the same dir with the jar-executable

    Hi,
    I need to read/write a file that exists in the same directory with the jar-executable. How can i do that? I think that when i specify no path for the file, the file has to be in current path. (Is that right?)
    Note: I do not know in which directory the jar and the file are.
    Thanx in advance

    Hi,
    I need to read/write a file that exists in the same
    directory with the jar-executable. How can i do that?
    I think that when i specify no path for the file, the
    file has to be in current path. (Is that right?)
    Note: I do not know in which directory the jar and
    the file are.
    Thanx in advance
    When you specify no path for the file, the file has to be in the directory where the virtual machine was started. ( the directory the java command was invoked in .)
    If you can't control the directory in which the vm is started, but you know the name of the .jar file you can do the following. This trick takes advantage of the fact that if you are using classes in a jar file, the name of the jar file must be in your classpath.
    public static String getPathOfJar( String nameOfJar )
    throws Exception
    StringTokenizer st = new StringTokenizer(
    System.getProperty( "java.class.path" ) ,
              System.getProperty( "path.separator" ) );
    String jarfile = "";
    while ( st.hasMoreTokens() )     
    String token = st.nextToken();
    if ( token.indexOf( nameOfJar ) > -1 )
    jarfile = token;
    break;
    if ( jarfile.equals("") ) throw new Exception( "Jar not found in classpath" );
    String path = jarfile.substring( 0 , jarfile.indexOf( nameOfJar ) );
    return path;
    //To open a file in the same directory as the sun archive tools.jar
    File f = new File( getPathofJar( "tools.jar" ) + "someFile.txt" );

  • Two profile two thunderbird at the same time with same user account

    Dear,
    I would use two Thunderbird at the same time for two different profiles with the same user accounts.
    I using linux OS.
    I was thinking of using:
    # thunderbird -P profile1 &
    # thunderbird -P profile2 &
    But when launching the second command nothing happens.
    Only brings in the foreground thundirbird already started.
    If possible use this configuration now or in the nex future?

    As a rule thunderbird only runs one instance of a profile.
    However, there are a couple of options you could try.
    You could use an addon to esily switch profiles:
    * https://addons.mozilla.org/en-US/thunderbird/addon/profileswitcher/
    there is more help here:
    * http://kb.mozillazine.org/Run_multiple_copies_of_Thunderbird_at_the_same_time
    It does say: 'Multiple instances is intended for debugging, so use it at your own risk'.
    One method would be to use: Start > Run
    "C:\Program Files\Mozilla Thunderbird\thunderbird.exe" -no-remote -P profilename
    there is a space before '-no'
    and also before '-P'
    followed by a space and the profile name
    You could create a shortcut/icon to run each separate profile.

  • WS-SDK Scheduling two instances of the same report with different params

    I'm using the web services SDK for Business Objects XI 3.1 SP 2 to schedule reports. I've got it so that I can successful schedule a report with prompts, setting the value for the prompt and running the report.
    However, I'm now trying to schedule two instances of the same report using a single call to BIPlatform.Schedule. It creates the correct number of new instances, the last of which is completely correct. The first one (and in fact if I do more than two all the rest except the last) lose the parameter value from the prompt and the schedule information and the type. So for example if I schedule two instances, both PDF, both for 8am tomorrow with parameters of 1 and 2, I get:
    A Webi instance, scheduled to run immediately with no parameters specified and
    A PDF instance, scheduled for 8am tomorrow with parameter 2
    Any idea what I'm doing wrong?
    Cheers,
    Jack
    Edited by: Jackson Pope on Feb 3, 2011 1:34 PM

    Can you possibly post your code here that sets params and schedules? Also as you schedule 2 instances on a single report in a sinlgle biplatform.schedule call(): as you query for InfoObject what you actually query for a single report isn't it, or do you schedule a report template and reschdule it previous instance?

  • How Write a Program to send  TWO attachments in the same  mail.

    Hello,
    How to write a ABAP program so that when u run this program   it shd send two 0r more files as an attachment.
    Presently i know how to send a single attachment but not the multiple attachment.
    i.e. by using "send_api" function module .
    please reply ASAP i need this urgently.

    this is simpple FM which can can send any type of Attachment.
    FUNCTION zsend_mail_attachment.
    *"*"Local interface:
    *"  IMPORTING
    *"     REFERENCE(V_FILE_PATH) TYPE  STRING OPTIONAL
    *"     REFERENCE(V_SUBJECT) TYPE  SO_OBJ_DES
    *"  TABLES
    *"      IT_RECEIVERS STRUCTURE  SOMLRECI1
    *"      IT_MESSAGE STRUCTURE  SOLISTI1
      DATA: gd_cnt TYPE i,
            gd_sent_all(1) TYPE c,
            gd_doc_data LIKE sodocchgi1,
            gd_error TYPE sy-subrc.
      DATA objbin LIKE solisti1 OCCURS 0 WITH HEADER LINE.
      DATA : it_packing_list LIKE sopcklsti1 OCCURS 0 WITH HEADER LINE.
    * Binary store for File
      DATA : BEGIN OF it_file OCCURS 0,
               row(255),
             END OF it_file.
    * splitting of the filepath
      DATA : BEGIN OF i_split OCCURS 0,
               row(50),
             END OF i_split.
      DATA tab_lines LIKE sy-tabix.
      REFRESH : it_file, objbin, it_packing_list, i_split.
      CLEAR   : it_file, objbin, it_packing_list, i_split.
      DESCRIBE TABLE it_message LINES tab_lines.
      READ     TABLE it_message INDEX tab_lines.
      gd_doc_data-doc_size = ( tab_lines - 1 ) * 255 + STRLEN( it_message ).
      gd_doc_data-obj_langu  = sy-langu.
      gd_doc_data-obj_name   = 'SENDFILE'.
      gd_doc_data-obj_descr  = v_subject.
      gd_doc_data-sensitivty = 'O'.
      CLEAR it_packing_list.
      it_packing_list-head_start = 1.
      it_packing_list-head_num   = 0.
      it_packing_list-body_start = 1.
      it_packing_list-doc_type   = 'RAW'.
      it_packing_list-body_num   = tab_lines.
      APPEND it_packing_list.
      IF v_file_path IS NOT INITIAL.
        DATA : v_len      TYPE i,
               v_index    LIKE sy-index,
               v_doc_type TYPE  so_obj_tp,
               v_filename TYPE  so_obj_des .
        v_len = STRLEN( v_file_path ) - 3.
        v_doc_type = v_file_path+v_len(3) .
        TRANSLATE v_doc_type TO UPPER CASE .
        SPLIT v_file_path AT '' INTO TABLE i_split .
        DESCRIBE TABLE i_split LINES v_index .
        READ TABLE i_split INDEX v_index .
        v_filename = i_split-row .
        v_len = STRLEN( v_filename ) - 4.
        v_filename = v_filename(v_len) .
        CALL FUNCTION 'GUI_UPLOAD'
          EXPORTING
            filename = v_file_path
            filetype = 'BIN'
          TABLES
            data_tab = it_file.
        LOOP AT it_file.
          MOVE it_file-row TO objbin-line.
          APPEND objbin.
        ENDLOOP.
        CLEAR it_packing_list.
        DESCRIBE TABLE objbin LINES tab_lines.
        it_packing_list-transf_bin = 'X'.
        it_packing_list-head_start = 1.
        it_packing_list-head_num   = 1.
        it_packing_list-body_start = 1.
        it_packing_list-doc_type   = v_doc_type.
        it_packing_list-body_num   = tab_lines.
        it_packing_list-doc_size   = tab_lines * 255.
        it_packing_list-obj_descr  = v_filename.
        APPEND it_packing_list.
      ENDIF.
    *  it_receivers-receiver = '[email protected]'.
    *  it_receivers-rec_type = 'U'.
    *  it_receivers-com_type = 'INT'.
    *  APPEND it_receivers .
    * Call the FM to post the message to SAPMAIL
      CALL FUNCTION 'SO_NEW_DOCUMENT_ATT_SEND_API1'
        EXPORTING
          document_data = gd_doc_data
          put_in_outbox = 'X'
          commit_work   = 'X'
    *   IMPORTING
    *     sent_to_all = gd_sent_all
        TABLES
          packing_list = it_packing_list
          contents_txt = it_message
          contents_bin = objbin
          receivers    = it_receivers
        EXCEPTIONS
          too_many_receivers         = 1
          document_not_sent          = 2
          document_type_not_exist    = 3
          operation_no_authorization = 4
          parameter_error            = 5
          x_error                    = 6
          enqueue_error              = 7
          OTHERS                     = 8.
    ENDFUNCTION.
    i have made it for only one attchmenet, for multiple attachmenet u can make more parameters <b>v_file_path_1, v_file_path_2, v_file_path_3</b> like wise do the coding as i have done for <b>v_file_path</b>
    hope this will solves ur query.....
    abhishek

  • Send two signals at the same time to serial

    Hi
    I have a problem in that I want to control some relay boards by serial. The boards have an address byte (to determine which of the three relay boards) and a relay combination (four relays on each board). The .vi I will need to make will be sending data to the serial as a result of feedback from sensors (they are currently simply controlled by timers to simulate) so there is a good chance that there will be two relay addresses sent at the same time and consequently much confusion. The timed simulation demonstrates this possibility by switching all relays on at the start.
    Is there a way of avoiding this? Any help would be much appreciated.
    Many thanks
    Alastair

    Alastair,
    When you say send to multiple boards "at the same time" exactly what to you mean? On a serial port only one byte at a time can be sent. You do not specify how many bytes are sent to each board to handle the addressing, the data, and any EOT (End of Transmission) characters.
    I can think of two possibilities.
    1. Relays are slow. If the transmission rate is fast enough, you could send messages to all relays sequentially over the serial port but still have the appearance of simultaneous activation of the relays. If the relays switch in 10 ms and each command contains 6 bytes, sending the data at 115 kilobaud would take about 1.5 ms for three boards. This would likely be close enough to simultaneous for relays.
    2. Add a command similar to the GPIB GET (Group Execute Trigger). All devices on the bus respond to this command by executing a previously stored command. No addressing is used for this command. This does require that the relay boards be modified to respond to their address and to the common or group address and to store a command for later execution.
    Lynn

  • How to run two icalenders on the same computer?

    How can i run two separate icalenders on the same computer? I have my own icalender with work, home, etc, and it's totally full. I am now running an artists collective and will publish the collectives icalender on the web. I don't, however, want to mix what will be a pretty busy calender with my own already too full one. Is it possible to run two totally separate calenders on the same computer?
    macbook   Mac OS X (10.4.8)  

    trsv,
    Welcome to Apple Discussions.
    Create two Groups...
    Calendar 1:
    Work
    Home
    etc
    Calendar 2:
    Collective Calendar
    You can then switch which groups you wish to display by activating/deactivating the check mark in the Calendar source window.
    That will also allow you to selectively publish the Collective Calendar.
    ;~)

  • How to process two files at the same time using BPM

    Hi experts,
    I have a Integration Process it takes two files one Header xml and one Lines xml. These files shoudl be processed at the same time because them will be mappend in a Idoc.
    The realy trouble is that these inbound xmls never are executed at the same time. Then a IP is executed for each inbound xml.
    This is the IP:
    http://picasaweb.google.com/hose86/SapXi#5377539387476591346
    This is related documentation:
    http://help.sap.com/saphelp_nwpi71/helpdata/en/cb/15163ff8519a06e10000000a114084/frameset.htm
    I try to do all what I know, but It don't work fine :S
    Thanks in advance and Regards,
    Jose Antonio.

    Hi Jose,
    Don't specify any end condition for  fork step and check the start process check box in both the receive step.
    Also put all steps inside the block.. so that the control step in deadline branch can throw exception and after that the BPM ends. As per the design now, if a deadline exception is raised (it will b handled) but after that the transformation step and send step is executed. There the BPM fails.
    Regards
    Suraj
    Edited by: S.R.Suraj on Sep 4, 2009 5:39 AM

  • How to play two videos at the same time

    Hi everyone!
    Ok, so what I'm trying to do is basically play two videos, which are already saved on the computer, at the same time. I can get one video to play, but when i try to start another it just displays a blank screen.
    import javax.swing.*;
    import javax.media.*;
    import java.awt.*;
    import javax.media.protocol.*;
    public class TwoVideoTest {
         public static void main(String[]args) {
         MediaLocator locator1 = null;
         MediaLocator locator2 = null;
         try {
         locator1 = new MediaLocator("file:/C:/truck1.mpg");
         locator2 = new MediaLocator("file:/C:/truck2.mpg");
         } catch(Exception e) {
         System.out.println("COULNDT CREATE LOCATORS IN MAIN TEST CLASS");
                          System.exit(-1);
         Player player1 = null;
         Player player2 = null;
                     try {
          player1 = Manager.createRealizedPlayer(locator1);
         player2 = Manager.createRealizedPlayer(locator2);
                      } catch(Exception e) {
              System.exit(0);
         JFrame frame = new JFrame();
         frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        JPanel panel1 = new JPanel();
       JPanel panel2 = new JPanel();
        panel1.add(player1.getVisualComponent());
       frame.getContentPane().add(panel1);
       frame.setSize(new Dimension(500,500));     
       frame.setVisible(true);
       player1.start();
       player2.start();
    }

    HELLO AGAIN! I guess i post too soon....
    So i modified my code and now the videos play together. Threads, sigh.
    But the audio that comes with the video doesn't appear to be starting at the same time. And this problem I ASSURE you i have no clue how to handle. And yes i know, the two video audios will overlap, but this a test for heavens sake!
    Anyways, heres the modified code in case it will help anyone
    import javax.swing.*;
    import javax.media.*;
    import java.awt.*;
    import javax.media.protocol.*;
    public class Video implements Runnable{
         String url;
         MediaLocator locator;
         Player player;
         JPanel panel;
         public Video (String url,JPanel panel) {
              this.url = url;
              try {
                   locator = new MediaLocator(url);
                   player = Manager.createRealizedPlayer(locator);     
                   panel.add(player.getVisualComponent());
                   player.start();
              } catch (Exception e) {
                   System.out.println("ERROR CREATING MEDIALOCATOR");
                   System.exit(-1);
         public void run() {
              try {
              Thread.sleep(100);
              } catch(Exception e) {}
         public static void main(String[]args) {
            JFrame frame = new JFrame();
              frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
              JPanel panel1 = new JPanel();
              JPanel panel2 = new JPanel();
              panel1.setPreferredSize(new Dimension(100,100));
              panel2.setPreferredSize(new Dimension(100,100));
              Thread thread1 = new Thread(new Video("file:/C:/truck1.mpg",panel1));
              Thread thread2 = new Thread(new Video("file:/C:/truck2.mpg",panel2));
              frame.getContentPane().add(panel1);
              frame.getContentPane().add(panel2);
              frame.setSize(new Dimension(500,500));     
              frame.setVisible(true);
              thread1.start();
              thread2.start();
         

Maybe you are looking for

  • How can I do to restart my questions

    how can I do to restart my answers for the security questions as I forgot then and cannot proceed with purchasing

  • How to document a labview project

    Hi, I 'm involved a labview programming project. After I have finished all my VIs. I need to document them, so that the next person who will take over me, know how the VIs work. how am I going to do that? Can anyone suggest some good URL or can uploa

  • Recommendations for a 2-Node Messaging 6.3 Cluster

    Hi all, I'm in the process of building a 2-node cluster to run Messaging Server 6.3 and would like your help. My question is in regard to the layout of the messaging software. For example, should I install the messaging binaries on each node of the c

  • Creating dispatcher scripts

    Hi, I am working IDM 7.1 SP04, I have created a new dispatcher with the host name and when I try to create scripts following error occurs. " Runtime error 381 Invalid property array index". I am unable to test the dispatcher as the scripts are not cr

  • Can't update Bootcamp to 2.1

    Okay, so I need to install the drivers for windows. This means I need service pack 3. I can't install service pack 3 because I have Bootcamp 2.0. I downloaded the bootcamp 2.1 update, burned it to a CD, then booted up windows to install it. I double