httpresponse - can not send response message from httpserver created using java -
i creating httpserver in application, using:
httpserver server = httpserver.create(new inetsocketaddress(8000), 0); this server first send response message using
outputstream os = httpex.getresponsebody(); os.write(("your request being handled, please wait").getbytes()); and opens 1 jfilechooser. if goes wrong throw error using
os.write(("failed handle request").getbytes()); when application runs on user's machine, creates httpserver properly, find through logs when user sends request server, nothing happens. displays blank page. when remove os.write lines works fine , displays filechooser pop-up. not aware going wrong. please me on this. have tried these approaches:
try { os.write(("your request being handled, please wait").getbytes()); os.close(); //code open jfilechooser pop-up } catch (exception e) { os.write(("failed handle request because"+e.getmessage()).getbytes()); os.close();} and
try { os.write(("your request being handled, please wait").getbytes()); //code open jfilechooser pop-up } catch (exception e) { os.write(("failed handle request because"+e.getmessage()).getbytes()); } os.close();
solved it. have added os.flush(); as:
finally(){ os.flush(); os.close(); is.close(); httpex.close(); }
Comments
Post a Comment