HttpURLConnection : Can you tell me what's wrong here ?

Hi,
here are to bloks of code, one for a client side, the second one for the server side.
The client is a simple app sending a request to a servlet
The second one is the servlet.
Before inserting the code, I describe my problem :
The client send a http request, get the response from the servlet and display the response.
The servlet get the content of the http request and send it back to the client.
Client side :
import java.net.*;
import java.io.*;
public class CallingServlet1
public static void main(String[] args)
String myUrl = "http://localhost:8080/myApp/servlet/UploadServlet";
try
URL url = new URL (myUrl);
HttpURLConnection cxn = (HttpURLConnection)url.openConnection();
cxn.setRequestMethod("POST");
cxn.setUseCaches(false);
cxn.setDoOutput(true);
cxn.setDoInput(true);
ByteArrayOutputStream bytes = new
ByteArrayOutputStream(400);
PrintWriter writer = new PrintWriter (bytes,true);
writer.print("my content.");
writer.flush();
cxn.setRequestProperty("Content-Length",String.valueOf(bytes.size()));
cxn.setRequestProperty("Content-Type","application/x-www-form-urlencoded");
bytes.writeTo( cxn.getOutputStream() );
String currentLine;
BufferedReader in = new BufferedReader (new InputStreamReader(cxn.getInputStream(),"8859_1"));
while((currentLine = in.readLine()) != null) {
System.out.println(currentLine);
catch(Exception e) { e.printStackTrace(); }
Server side :
import java.io.*;
import java.util.*;
import java.net.*;
import javax.servlet.*;
import javax.servlet.http.*;
public class UploadServlet extends HttpServlet
static final String dir="C:/temp";
public void doPost(HttpServletRequest req, HttpServletResponse res) throws ServletException, IOException
ServletOutputStream output = res.getOutputStream();
int content_length = req.getContentLength();
output.println("ContentLength: " + content_length + "<BR>");
if(content_length > 0) {
InputStream input;
input = req.getInputStream();
BufferedInputStream in = new BufferedInputStream(input);
BufferedReader reader = new BufferedReader( new InputStreamReader(in) );
for ( int j=0; j<content_length; j++ )
int i = reader.read();
output.println( String.valueOf(i) );
in.close();
So now, no problem with the previous code.
The problem is that if in the server side, instead of the code
for ( int j=0; j<content_length; j++ )
int i = reader.read();
output.println( String.valueOf(i) );
I put a
while ((i = reader.read()) != -1)
output.println( String.valueOf(i) );
the program doesn't stop and, after this first step, I have to replace the while by giving the content to a xmlParser that will not work in this situation
Please, help.

I think that my problem is I don't know how to say that the content has been fully sent to the server and then pass in a wait mode for the response so that the servlet will receive something like a (eof) instead of stay waiting for others elements.

Similar Messages

  • When I startup Itunes I get "An Unknown Error Occurred -42110" Message.  Can you tell me what is wrong and how to resolve?

    When I startup Itunes I get "An Unknown Error Occurred -42110" Message.  Can you tell me what is wrong and how to resolve?

    Try the following user tip:
    iTunes for Windows 11.0.2.25 and 11.0.2.26: "Unknown error -42110" messages when launching iTunes

  • I have i pad 2 ios 4.3.1 i want to update it to 4.3.3 but i get error msg 3194 can you tell me what's wrong with apple some people talking about apple don't veryfiy 4.3.3 anymore thanks alot

    i have i pad 2 ios 4.3.1 i want to update it to 4.3.3 but i get error msg 3194 can you tell me what's wrong with apple some people talking about apple don't veryfiy 4.3.3 anymore thanks alot

    4.3.5 is the current version, so that is the version that iTunes will download, not 4.3.3
    In terms of error 3194, have you got the latest version of iTunes on your computer ? - http://support.apple.com/kb/TS3694#error3194

  • I keep getting this error in Dreamweaver when I am trying to upload my website?  Can you tell me what I am doing wrong?  here is the error message: /html - error occurred - Unable to create remote folder /html.  Access denied.  The file may not exist, or

    I keep getting this error in Dreamweaver when I am trying to upload my website?  Can you tell me what I am doing wrong?  here is the error message: /html - error occurred - Unable to create remote folder /html.  Access denied.  The file may not exist, or there could be a permission problem.   Make sure you have proper authorization on the server and the server is properly configured.  File activity incomplete. 1 file(s) or folder(s) were not completed.  Files with errors: 1 /html

    Nobody can tell you anything without knowing exact site and server specs, but I would suspect that naming the folder "html" wasn't the brightest of ideas, since that's usually a default (invisible) folder name existing somewhere on the server and the user not having privileges to overwrite it.
    Mylenium

  • Can you tell me what i pay for. From my visa account itunes is collecting money on 15 sept, 4 sept, 1 sept etc and i do not know for what. I have not download  apps i have to pay for

    Hello, can you tell me what i pay for. Itunes is collecting money form my visa on certain days of the month (for example on 15 september, on 12 september on 1 september etc). I have not downloaded apps for which i have tp pay. Do i have done something wrong or what???

    It sounds like you may have subscriptions.
    If you want to view your app subscriptions:
    From your device's Home screen, tap App Store.
    Tap Featured at the bottom of the screen.
    Scroll to the bottom of the page.
    Tap the Apple ID button in the lower-left corner. (If you are not signed in, tap the Sign In button, and sign in with your Apple ID. Then, scroll back to the bottom of the page, and tap the Apple ID button.)
    Tap the View Apple ID button.
    Enter your password and tap OK.
    From the main account page, scroll down and tap Manage App Subscriptions. If you don't have app subscriptions this button will not be displayed.
    You'll then be taken to your App Subscriptions page.
    To turn off auto-renewal:
    From your Manage App Subscription page, choose an app subscription. 
    Tap the subscription category for which you want to disable auto-renewal.
    Tap On to toggle the switch to Off.
    You'll receive a confirmation message; tap Turn Off to confirm your choice.
    To turn off auto-renewal on computer:
    Launch iTunes on your computer.
    Choose Store > Sign In from the iTunes menu.
    Enter your Apple ID and password when prompted.
    Choose Store > View My Account. You may be asked to re-enter your Apple ID password. Click View Account .
    From the Account Information screen, scroll to the bottom of the page to the Settings section.
    Click Manage to the right of Subscriptions.
    From the Manage Subscription screen click on the subscription that you would like to manage.
    On the Edit Subscription screen, you will see the current subscription status and subscription details.
    Click the Off radio button to turn off Auto-Renewal.
    You will see a confirmation window asking you to confirm.
    Click Continue to proceed.
    Note: When you turn off auto-renewal, you will no longer continue to be billed for your subscription, however your subscription will continue until it expires.

  • My ipod had a full battery but when i took it off charge and put my earphones in it it went completley dead and hasnt come back on. Can anybody tell me what is wrong and how to fix it?

    my ipod had a full battery but when i took it off charge and put my earphones in it, it went completly dead and hasnt come back on.  Can anybody tell me what is wrong and how to fix it?

    Try here to fix it.  I doubt that you will ever find out why it did that.
    iPod touch: Hardware troubleshooting

  • Can you tell me what this code does?

    Can you tell me what this code does?
    import java.io.*;
    class Assignment1
    public static String[][] tdi = {     {"Paris", "418", "Rome", "55"},
                             {"Liverpool", "121", "Copenhagen", "35"},
                             {"Liverpool", "418", "Paris", "50"},
                             {"Liverpool", "553", "Frankfurt", "55"},
                             {"Frankfurt", "553", "Budapest", "50"},
                             {"Amsterdam", "121", "Madrid", "65"},
                             {"Amsterdam", "418", "Paris", "35"},
                             {"Madrid", "121", "Stockholm", "90"},
                             {"Budapest", "553", "Warsaw", "30"},
                             {"Copenhagen", "121", "Amsterdam", "35"},
                             {"Rome", "418", "Amsterdam", "60"},
    //--Start Method--
    public static void main( String args[] ) throws IOException
    System.out.println("Welcome to NoWings Airline.");
    InputStreamReader input = new InputStreamReader(System.in);
    BufferedReader keyboardInput = new BufferedReader(input);
    System.out.println("Please enter the airport you wish to depart from:");
    String[] info = TDIDLL.searchDest( keyboardInput.readLine() );
    if (info == null)
    System.out.println("Sorry, no plane to this destination");
    else
    System.out.println(info[0]+" departing at platform "+info[1]); }}
    public static String[] searchDest( String dest )
    String[] result = null;
    for(int i = 0; i < tdi.length; i++)
         if (tdi[1].equals(dest)) {
         result = new String[2];
         result[0] = tdi[i][0];
         result[1] = tdi[i][2];
         return result;
    return result; }
    // Info Method //
    // Fly Method //
    // Exit Method //
    Thanks. Also, can you tell me where I have gone wrong in the code.
    Much appreciated.

    Can you tell me what this code does?Why don't you run it and find out for yourself?

  • I am using Mavericks. I had a list of VIPS and used it extensively. Now it has disappeared and VIPs on the menu bar is faded. There is nil response to VIP in help. Can you tell me what has happened?

    I am using Mavericks. In Mail I had a list of VIPS and used it extensively. Now it has disappeared and VIPs on the menu bar is faded. There is nil response to VIP in help. Can you tell me what has happened?

    Triple-click anywhere in the line below on this page to select it:
    ~/Library/Mail/V2/MailData/VIPSenders.plist
    Right-click or control-click the highlighted line and select
    Services ▹ Show Info in Finder (or just Show Info)
    from the contextual menu.* An Info dialog should open.
    Does the dialog show "You can read and write" in the Sharing & Permissions section?
    In the General section, is the box labeled Locked checked?
    What is the Modified date?
    If you don't have read and write access to the item, change the settings as directed here. Note, however, that if one file has wrong access settings, most likely others do as well. If the item is locked, unlock it.
    *If you don't see the contextual menu item, copy the selected text to the Clipboard by pressing the key combination command-C. Open a TextEdit window and paste into it (command-V). Select the line you just pasted and continue as above.

  • Is there any Sound card 5.1 include stereo mix that working with MacBook Air such as Creative Labs SoundBlaster X-Fi Surround 5.1 Pro Entertainment System ? and if there any another sound card can you tell me what is it please ? Thank you.

    Is there any Sound card 5.1 include stereo mix that working with MacBook Air such as Creative Labs SoundBlaster X-Fi Surround 5.1 Pro Entertainment System ? and if there any another sound card can you tell me what is it please ? Thank you.

    Okay, I did my best searching and I couldn't find anything that matched all your descriptors. I did do a search on both decoder numbers. SB0256 returned very little results, but with SB0466, I was able to find this ebay listing:
    http://cgi.ebay.com/ws/eBayISAPI.dll...6_fvi%3D&_rdc=
    This card isn't a Champion like you suggested. And with my complete lack of knowledge, I don't know what I/O dri've bay means. But since it is PCI and the decoder matches the number you gave me, this card should be adequete, right?
    Whether it works or not, my search indicated it might be very hard for me to find that card (or any PCI card for that matter). Everything I saw was out of stock. I know this is a forum for Creative, but are there any other manufacturers that will allow me to accomplish my goal, either with current cards, or discontinued cards? Thanks again
    Oh, and I will vote on that thread. I probably won't wait for them to release the decoder since I need it now, but I still believe Creative should be giving the customer what they want

  • Can you tell me what is the function modue to get POPUP box

    Hi Folks,
    can you tell me what is the function module to get the POPUP box.
    Thanks in Advance,
    Lakshmi

    Hai use
    POPUP_TO_CONFIRM
    check the following Code
    CONCATENATE 'Send selected spools to the: '
                 altdest
                ' Printer.' INTO V_TXTQUES SEPARATED BY SPACE.
    CALL FUNCTION 'POPUP_TO_CONFIRM'
      EXPORTING
        TITLEBAR                    = C_TITLEBAR
      DIAGNOSE_OBJECT             = ' '
        TEXT_QUESTION               = V_TXTQUES
      TEXT_BUTTON_1               = 'Ja'(001)
      ICON_BUTTON_1               = ' '
      TEXT_BUTTON_2               = 'Nein'(002)
      ICON_BUTTON_2               = ' '
      DEFAULT_BUTTON              = '1'
       DISPLAY_CANCEL_BUTTON       = ' '
      USERDEFINED_F1_HELP         = ' '
       START_COLUMN                = 6
       START_ROW                   = 6
      POPUP_TYPE                  =
      IV_QUICKINFO_BUTTON_1       = ' '
      IV_QUICKINFO_BUTTON_2       = ' '
      IMPORTING
        ANSWER                      = D_ANSWER
    TABLES
      PARAMETER                   =
    EXCEPTIONS
       TEXT_NOT_FOUND              = 1
       OTHERS                      = 2.
    IF SY-SUBRC <> 0.
    MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
            WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
    ENDIF.
    IF D_ANSWER = '1'.
    Thanks & regards
    Sreenivasulu P

  • Help! We have a form with more than 200 entries and when I looked at it yesterday it had one! When you download the form to excel they all show up. However, when I added another record today it disappeared. Can you tell me what's happening? I've been usin

    Help! We have a form with more than 200 entries and when I looked at it yesterday it had one! When you download the form to excel they all show up. However, when I added another record today it disappeared. Can you tell me what's happening? I've been using adobe forms for 2 years with mass response feedback and have never had this problem.

    Greetings,
    I've never seen this issue, and I handle many iPads, of all versions. WiFi issues are generally local to the WiFi router - they are not all of the same quality, range, immunity to interference, etc. You have distance, building construction, and the biggie - interference.
    At home, I use Apple routers, and have no issues with any of my WiFi enabled devices, computers, mobile devices, etc - even the lowly PeeCees. I have locations where I have Juniper Networks, as well as Aruba, and a few Netgears - all of them work as they should.
    The cheaper routers, Linksys, D-Link, Seimens home units, and many other no name devices have caused issues of various kinds, and even connectivity.
    I have no idea what Starbucks uses, but I always have a good connection, and I go there nearly every morning and get some work done, as well as play.
    You could try changing channels, 2.4 to 5 Gigs, changing locations of the router. I have had to do all of these at one time or another over the many years that I have been a Network Engineer.
    Good Luck - Cheers,
    M.

  • On my new iPad under the space category it shows I have 5.5gb occupied by 'Other" data - Can you tell me what this is exactly and how can I reduce it Thank-you

    On my new iPad under the space category it shows I have 5.5gb occupied by 'Other" data - Can you tell me what this is exactly and how can I reduce it
    Thank-you

    How Do I Get Rid Of The “Other” Data Stored On My iPad Or iPhone?
    http://tinyurl.com/85w6xwn
    With an iOS device, the “Other” space in iTunes is used to store things like documents, settings, caches, and a few other important items. If you sync lots of documents to apps like GoodReader, DropCopy, or anything else that reads external files, your storage use can skyrocket. With iOS 5, you can see exactly which applications are taking up the most space. Just head to Settings > General > Usage, and tap the button labeled Show All Apps. The storage section will show you the app and how much storage space it is taking up. Tap on the app name to get a description of the additional storage space being used by the app’s documents and data. You can remove the storage-hogging application and all of its data directly from this screen, or manually remove the data by opening the app. Some applications, especially those designed by Apple, will allow you to remove stored data by swiping from left to right on the item to reveal a Delete button.
     Cheers, Tom

  • Can you tell me what is a pass code for re setting program and where can I find it?

    Can you tell me what is a pass code for re setting program and where can I find it?

    For resetting what program? What are you trying to do? When you have a problem, please provide enough info to answer.
     Cheers, Tom

  • "CAHeadless error Sequence.cpp-2233" after computer starts up.  Can you tell me what this is or how to fix it?  Thanks!

    Since installing Adobe Premier Elemnts 12 I get a message that says "CAHeadless error Sequence.cpp-2233" after computer starts up.  Can you tell me what this is or how to fix it?  Thanks!

    If you are using Firefox 3.6.6 version, open Tools > Options >> Advanced - Network
    The under Connections hit the Settings button - then select '''No proxy''' at the top of those settings. Restart Firefox and you should be all set.
    ''(3.6.6 added a new setting there - Use system proxy settings and sets that as the Default setting)''

  • HT4623 I Have Iphone 3G, But There Is Not Here Software Update Option.. Can You Tell Me What Can I Do?

    I Have Iphone 3G, But There Is Not Here Software Update Option.. Can You Tell Me What Can I Do?

    Muhammad Tariq Khan wrote:
    I Have Iphone 3G, ...
    The iPhone 3G can only update as far as iOS 4.2.1
    Muhammad Tariq Khan wrote:
    ... There Is Not Here Software Update Option..
    that is Only a feature of iOS 5 or later.

Maybe you are looking for

  • Regarding JDBC Driver Connectivity

    Hi All, Presently we are using DB6 data base and how can i get JDBC driver information and connection paramters those are required for Implementing JDBC Adapters in XI. Please give u r inputs towards How can I find the connectivity details of Databas

  • Can I download 10.8 for free?

    Hello community. I purchased my first Apple product on Sunday, a Mac mini 6,1.  It came preinstalled with OS X 10.8.3 and included no installation media (which makes sense as the mini has no optical drive). As I've paid for an OS X 10.8 license alrea

  • Can I rearrange the order of my calendar groups?

    I am only able to drag a calendar group to the very top. I have several groups of calendars and would like to arrange them in a specific order and it will be frustrating to have to do it from the top down. If you don't know what I am talking about, c

  • Use of reader and voice over functions

    Want/need help using both "reader" and voice over functions.  Thank you.

  • My software download on Safari stopped.  What do I do?

    I was downloading the latest version of Photoshop Elements from their website and the download stopped about a quarter of the way through.  Why does this happen and what can I do?