Search code examples
javaswingservletshttpconnection

Display result on the browser from servlet where data is received from swing


I am passing data from swing to servlet using http url connection.I have passed usrname and password to servlet.I want to dispaly the result on the browser.I set Doinput to false so that the result will display on to the browser.But it is not happening.(Previously Doinput was true and I read the result using InputStream is = connection.getInputStream(),But the result was not on the browser,just out.println statements are returned from servlet.So i set it to false).What is the way to do it??

I have used Bare Bones Browser Launcher to open on to the browser,(I have given servlet path to Bare Bones Browser Launcher method).It is working fine,Browser is opening but nothing is getting displayed.(I have used out,println("hii") in the servlet;) just to check whether it is printing or not.What is the solution??


Solution

  • There is no way that an HTTP response goes to a browser if the corresponding HTTP request has not been sent by the browser, but an external Swing application.

    What you could do, is send the parameters from your swing app to your servlet, have the servlet store these parameters in memory or in a database or whatever, and have your swing app open a browser window to an URL of the same webapp that would display the parameters that have just been sent.

    But you need two requests:

    • one from the swing app to send the parameters
    • one from the browser to display the parameters