How to launch a browser with URLConnection content

Hi,
I'm new in Java programming, trying to write a Java application to send
something to server and get response through HTTP. By following some tutorial material, I did
import java.net.*;
import java.io.*;
public class URLConnectionReader {
    public static void main(String[] args) throws Exception {
        URL yahoo = new URL("http://www.yahoo.com/");
        URLConnection yc = yahoo.openConnection();
        BufferedReader in = new BufferedReader(
                                new InputStreamReader(
                                yc.getInputStream()));
        String inputLine;
        while ((inputLine = in.readLine()) != null)
            System.out.println(inputLine);
        in.close();
}And got the source HTML. But how can I launch a default browser and send the header and HTML to the browser?
Thanks.

Hi,
Thanks for the solutions. I'm more interested in the 2nd solution.
However, when I tried it, the thread never returns from ss.accept().
Here is the code I wrote. Can you tell me what I did wrong?
Thanks.
import java.net.*;
import java.io.*;
public class URLConnectionReader {
   public static void main(String[] args) throws Exception {
      URL url = new URL("http://www.yahoo.com");
      HtmlRelay relay = new HtmlRelay(url);
      relay.run();
      Runtime.getRuntime().exec("mozilla http://localhost:8080");
class HtmlRelay extends Thread
  URL url;
  public HtmlRelay(URL u) { url = u; }
  public void run()
     try {
        URLConnection urlc = url.openConnection();
        BufferedReader in = new BufferedReader(
                               new InputStreamReader(
                               urlc.getInputStream()));
        final ServerSocket ss = new ServerSocket(8080);
        System.out.println(ss.toString());
        Socket accept = ss.accept();
        System.out.println(accept.toString());
        OutputStreamWriter os = new
OutputStreamWriter(accept.getOutputStream());
        BufferedWriter ou = new BufferedWriter(os);
        String inputLine;
        while ((inputLine = in.readLine()) != null)
            ou.write(inputLine);
            System.out.println(inputLine);
        ou.flush();
        ou.close();
        in.close();
     } catch (Exception e) {
         e.printStackTrace();
}

Similar Messages

  • How could I transport package with all content within

    How could I transport package with all content ( I do not get it with se80->"write transport entry") or by entering in se10 in transport request object R3TR DEVC.

    go to SE03
    choose the third item "include objects in a request" by double-clicking
    there you set the first parameter "Package" to your package and execute
    note: you can also deselect the radiobutton "All objects" and set "Selected objects" then you will be able to fine-tune the list of objects

  • How to launch an application with elevated administrator account privilege from windows service even if the account has not yet logon

    Here is the case:
    OS environment: Windows 7
    There are two user accounts in my system, standard user "S" and administrator account "A", and there is a windows service running with "Local System" privilege.
    Now i logged-in with account "S", and i want to launch an application with elevated administrator account "A" from that service program, so here is the code snippet:
    int LaunchAppWithElevatedPrivilege (
    LPTSTR lpszUsername, // client to log on
    LPTSTR lpszDomain, // domain of client's account
    LPTSTR lpszPassword, // client's password
    LPTSTR lpCommandLine // command line to execute e.g. L"C:\\windows\\regedit.exe"
    DWORD dwExitCode = 0;
    HANDLE hToken = NULL;
    HANDLE hFullToken = NULL;
    HANDLE hPrimaryFullToken = NULL;
    HANDLE lsa = NULL;
    BOOL bResult = FALSE;
    LUID luid;
    MSV1_0_INTERACTIVE_PROFILE* profile = NULL;
    DWORD err;
    PTOKEN_GROUPS LocalGroups = NULL;
    DWORD dwLength = 0;
    DWORD dwSessionId = 0;
    LPVOID pEnv = NULL;
    DWORD dwCreationFlags = 0;
    PROCESS_INFORMATION pi = {0};
    STARTUPINFO si = {0};
    __try
    if (!LogonUser( lpszUsername,
    lpszDomain,
    lpszPassword,
    LOGON32_LOGON_INTERACTIVE,
    LOGON32_PROVIDER_DEFAULT,
    &hToken))
    LOG_FAILED(L"GetTokenInformation failed!");
    __leave;
    if( !GetTokenInformation(hToken, (TOKEN_INFORMATION_CLASS)19, (VOID*)&hFullToken,
    sizeof(HANDLE), &dwLength))
    LOG_FAILED(L"GetTokenInformation failed!");
    __leave;
    if(!DuplicateTokenEx(hFullToken, MAXIMUM_ALLOWED, NULL,
    SecurityIdentification, TokenPrimary, &hPrimaryFullToken))
    LOG_FAILED(L"DuplicateTokenEx failed!");
    __leave;
    DWORD dwSessionId = 0;
    WTS_SESSION_INFO* sessionInfo = NULL;
    DWORD ndSessionInfoCount;
    bResult = WTSEnumerateSessions(WTS_CURRENT_SERVER_HANDLE, 0, 1, &sessionInfo, &ndSessionInfoCount);
    if (!bResult)
    dwSessionId = WTSGetActiveConsoleSessionId();
    else
    for(unsigned int i=0; i<ndSessionInfoCount; i++)
    if( sessionInfo[i].State == WTSActive )
    dwSessionId = sessionInfo[i].SessionId;
    if(0 == dwSessionId)
    LOG_FAILED(L"Get active session id failed!");
    __leave;
    if(!SetTokenInformation(hPrimaryFullToken, TokenSessionId, &dwSessionId, sizeof(DWORD)))
    LOG_FAILED(L"SetTokenInformation failed!");
    __leave;
    if(CreateEnvironmentBlock(&pEnv, hPrimaryFullToken, FALSE))
    dwCreationFlags |= CREATE_UNICODE_ENVIRONMENT;
    else
    pEnv=NULL;
    if (! ImpersonateLoggedOnUser(hPrimaryFullToken) )
    LOG_FAILED(L"ImpersonateLoggedOnUser failed!");
    __leave;
    si.cb= sizeof(STARTUPINFO);
    si.lpDesktop = L"winsta0\\default";
    bResult = CreateProcessAsUser(
    hPrimaryFullToken, // client's access token
    NULL, // file to execute
    lpCommandLine, // command line
    NULL, // pointer to process SECURITY_ATTRIBUTES
    NULL, // pointer to thread SECURITY_ATTRIBUTES
    FALSE, // handles are not inheritable
    dwCreationFlags, // creation flags
    pEnv, // pointer to new environment block
    NULL, // name of current directory
    &si, // pointer to STARTUPINFO structure
    &pi // receives information about new process
    RevertToSelf();
    if (bResult && pi.hProcess != INVALID_HANDLE_VALUE)
    WaitForSingleObject(pi.hProcess, INFINITE);
    GetExitCodeProcess(pi.hProcess, &dwExitCode);
    else
    LOG_FAILED(L"CreateProcessAsUser failed!");
    __finally
    if (pi.hProcess != INVALID_HANDLE_VALUE)
    CloseHandle(pi.hProcess);
    if (pi.hThread != INVALID_HANDLE_VALUE)
    CloseHandle(pi.hThread);
    if(LocalGroups)
    LocalFree(LocalGroups);
    if(pEnv)
    DestroyEnvironmentBlock(pEnv);
    if(hToken)
    CloseHandle(hToken);
    if(hFullToken)
    CloseHandle(hFullToken);
    if(hPrimaryFullToken)
    CloseHandle(hPrimaryFullToken);
    return dwExitCode;
    I passed in username and password of account "A" to method "LaunchAppWithElevatedPrivilege", and also the application i want to launch, e.g. "C:\windows\regedit.exe", but when i run the service program, i found it do launch
    "regedit.exe" with elevated account "A", but the content of regedit.exe is pure back. screenshot as below:
    Can anyone help me on this?

    You code is not dealing with the DACL access to Winsta0\Default.  Only the LocalSystem account will have full access and the interactively logged on user which is why regedit is not displaying properly.  You'll need to grant access to your user. 
    You also need to deal with UAC since that code is going to give you a non-elevated token via LogonUser().  You need to get the full token via a call to GetTokenInformation() + TokenLinkedToken.
    thanks
    Frank K [MSFT]
    Follow us on Twitter, www.twitter.com/WindowsSDK.

  • How to launch a navigator with java

    I would like to know how we can launch navigators such as Netscape, internet Explorer or Opera with java
    thanks

    Nobody will answer you because of your appaling behaviour on the forum so far. I have to browse this forum in work, with colleugues around. This may sound silly, but it looks bad when I browse a forum with "I fuck Microsoft" posted on it, know what I mean?

  • How to launch an adapter with an external software ?

    Hi everybody,
    Is it possible to launch an adapter thanks to an EXTERNAL tools (software or Java program)? and how ?
    But... I have some constraints:    :-((
      - no use of BPM
      - no use of PCK
      - no use of "poll interval" option for a file adapter
      - no use of a Plain J2SE decentralized Adapter Engine
      - Adapters are these one of Integration Service's AE and especially: File, JDBC, SOAP.
    Example: I defined a sender file adapter which take a file inside a folder and give it to XI (cf. IR). But with all my constraints, I don't know how I can launch this "sleeping" actived adapter.
    Any helps/ideas are welcome !
    Mickael

    Hi,
    Yes, you understood my problem: it's just <u>to trigger an adapter with a remote call</u>.
    In fact, one want to find an easy solution for end-user. For them, it's just (thanks to a button) "I want to send my data to R/3" and that's all... They don't know that their data are inside a file or a table or a web service and they don't know that there is XI !
    Ananth, the HTTP solution is not efficient for us, because HTTP program needs to read a CSV file and transform it to a XML message before sending to XI. Thus in this case, it would be like if you RE-create the functionalities of a File Adapter in another system, whereas this one exist in standard in  XI => No interresting!
    Mickael

  • How to launch the dialog with a wizard having train component

    Hi
    I have a page with a button and onclicking the button i need to show a dialog wizard( a wizard with 3 pages with the train component to move back and forth)
    I have created a taskflow as a train with 3 pages, but onclicking the button i am not able to launch the dialog as a taskflow.
    Any documentatino on how to achieve the same or some sample application reference is highly appreciated
    Bittu Bansal

    On clicking the button i want to show a popup and that popup drives me through the wizard.
    However i am able to achive the same right now.
    I am calling a popup using showPopupBehaviour and that popup i have created the region where i have embedded the task flow for a train wizard.
    Thanks
    Bittu Bansal

  • How to launch integration builder with IE proxy?

    Hi,gurus:
    Our XI server is in remote side, so we have to set the IE proxy while launching integration server.But as you know,the integration builder woud not be launched successfully with IE proxy.So how can we deal with it?
    Any help will be appreciated!

    Hi,
    The error message is "unable to launch integration builder" ,which all of us might have ever met.
    I think it is the cause of IE proxy,but we have to set the proxy to get the environment from remote XI server.
    I have referenced note 800267,but it seems of no avail.
    Any ideas?

  • How to launch a browser from a java/MAC application

    I know, this topic has been brought up over, and over, however I couldn't find info regarding MAC environments. I don't have any former experience with MAC, but now I'm getting desperate for a solution. I need to be able to launch the default browser showing a certain URL on MAC/OS. Any clue would be appreciated.
    thanks,
    m. berdan

    I wrote libraies that will do this:
    http://ostermiller.org/utils/Browser.html
    I also keep a list of other resources to help you out:
    http://dmoz.org/Bookmarks/D/deadsea/Java_Help/Web_Browser/
    Stephen

  • How to create fillable PDF with dynamic content dropdowns?

    I'm creating a March Madness bracket for people that don't really understand how they work.  What I'd like to do is have dropdowns for each of bracket lines (they would list the teams playing against each other for that game and they would select who they think would win).  I would then like the dropdown for the next game to auto-populate with only the two options for the next round. 
    For example, team A and team B play against each other and teams C and D play against each other.  There are two separate dropdowns, one with A and B as choices and the other with C and D as choices.  The user thinks A and C will win their games, so the next dropdown would only have the options of selecting A and C.  To illustrate:
    AA and B are listed in the dropdown, and the user selects A to win.
    BA or C are listed in the dropdown because the user has selected A and C to win their previous games.
    CC and D are listed in the dropdown, and the user selects C to win.
    D
    I can make the first round dropdowns just fine, but I'm not sure how to conditionally/dynamically populate the second round dropdowns based off of user selections.

    I don't understand your request but my english is not the best.
    But here you can see a script. You can copy this in the first dropdown in the exit-event.
    In this example you will give the first dropdwon the entries
    "123"
    "345"
    "678"
    The first case describes what happens when the user clicks "123" the second drowdown will get the entries "456" and "789".
    When the user clicks "456" the second drowdown will get the entries "123" and "789".
    I think you can adapt this script as you need.
    Hope I could help a little bit,
    Mandy
    switch (xfa.event.newText)
        case "123":
            DropdownListe2.clearItems();
            DropdownListe2.addItem("Please select a value");
            DropdownListe2.addItem("456");
            DropdownListe2.addItem("789");
            DropdownListe2.selectedIndex = 0;
            break;
        case "456":
            DropdownListe2.clearItems();
            DropdownListe2.addItem("Please select a value");
            DropdownListe2.addItem("123");
            DropdownListe2.addItem("789");
            DropdownListe2.selectedIndex = 0;
            break;
        case "789":
            DropdownListe2.clearItems();
            DropdownListe2.addItem("Please select a value");
            DropdownListe2.addItem("123");
            DropdownListe2.addItem("456");
            DropdownListe2.selectedIndex = 0;
            break;
        default:
            break;

  • How to print a PDF with multimedia content?

    I have a 127 page PDF with flash files and other multimedia embedded. How do  go about printing this to a laser printer?

    Thank you Michael
    My problem is, I need to print the document with the mm items.  I work 
    in a print & copy shop, we must deal with whatever the customers send 
    us.
    I actually stumbled around and found I could do it with the MultiMedia 
    Flash Tool, editing the poster options. It's a tedious process though, 
    and I'd like to find a way to set this for the whole PDF file at once.
    If you know how to do this I'd appreciate the info.
    Thanks again,
    Mark

  • How to launch a .exe with another exe

    I use Labview 8.2
    I would like to know if it is possible to launch an application (supplying the path for exemple)(created also by Labview) via a specifc  Labview function inserted into another application.
    Thanks a lot
    Daniel. 

    Is what you are looking for the "System Exec.vi" found under Connectivity\Libraries & Executables ? It allows the launching of an executable, with command line input if appropriate, from within LabVIEW.
    Putnam
    Certified LabVIEW Developer
    Senior Test Engineer
    Currently using LV 6.1-LabVIEW 2012, RT8.5
    LabVIEW Champion

  • How to launch an App with Root privileges - without enabling "root" user ac

    Is there a reliable way to launch an Application so that it can run with "root" privileges, but without enabling the OSX root account and logging in to that account?
    There is an old (and, presumably, obsolete) application called "Pseudo" which used to facilitate this, but I doubt it would be safe or reliable under OSX 10.5.
    So, does anyone have any suggestions?

    For a more permanent method, run the following command on the same file:
    sudo chmod u+s
    if the item is owned by root. This may be undone by the repair permissions command.
    (27138)

  • How to print two pages with same content in sap script?

    I have created page1 and copied as page2. 1st page is  assigned with Tray1 and 2nd page is assigned with Page2.but while printing page1 is printing properly,but page2's main window values not printing(Note: page2 is not Next page). I need 2 copies printout of check from Tray1 and Tray2.How to do this?

    Hi ,
    do as following.
    Data: wa_options type ITCPO.
    wa_optinos-TDCOPIES = '2'.
    then call the function module.
    CALL FUNCTION 'OPEN_FORM'
    EXPORTING
    DEVICE = 'PRINTER'
    DIALOG = 'X'
    FORM = 'ZSAP'
    LANGUAGE = SY-LANGU
    OPTIONS = wa_options.
    I have given you for printing multiple copies
    But donno what do you mean by Tray 1 and tray 2 ?
    Regards,
    Nageswar

  • How Select All Text Objects with Specific Contents and Move to Top-Center?

    Mavens,
    In a ~230 page InDesign CC Book (9 INDD files), on about ~35 pages, there is a small text block with the word "NOTES."
    Currently, the NOTES text block is in the Middle-Center of the page. I would like to find a way for InDesign to move all ~35 instances of the NOTES text block to the Top-Center (of the page each text block is on).
    Is there an easy way to do this with Edit --> Find/Change?
    Thanks!

    Probably not.
    That text block really belongs on a master page applied to those 35 pages, and if it is, all you have to do is move it on the master page. If it isn't, you've got some work to do. Probably easiest to fix one, then coy it and use Paste in Place on the other pages, and delete the frame that's in the wrong place.

  • How to launch a finder with password requested, not using  sudo in terminal

    Hi,
       I would like to have a finder with password requested in Mac like we move the the driver in /System/Library/extensions folder to trash by command lines.  Using "sudo delete"  in terminal will have the DOS-style and not good-looking for users.  That is, I would like to have the GUI with password by some commands(or scripts) before I removing the driver.
    Thanks for your help.
    Jason

    You shouldn't be doing anything with system files. Those don't belong to you. If you need to install or update software in /Library, create an installer package. It will run as root, after prompting for administrator credentials.

Maybe you are looking for

  • Setting up a Digital Signature

    Hi all.  I have Adobe Acrobat X, and I'm trying to set up a digital signature with a graphic.  The graphic is actually a signature that is scanned. The problem is when I create the digital signature graphic, the graphic signature is very small and al

  • External libraries for IPhoto for iPad

    How can I access an IPhoto library created with IPhoto for Mac on a WhiFI NAS from IPhoto for IPad?

  • Dynamic variables

    I am working on a PL/SQL page process that would be able to update a large number of page items with a for loop. I can modify each item separately but I would like to be able to loop it. I used to know how to do something like that with PHP ($$variab

  • Tables not showing up

    i've oracle 10 g installed in my comp on windows.... till now it was working fine.... but now... when i start database n try to access tables through home - > object browser - > show tables ..... it's not showing any tables or home - > sql -> sql com

  • LAN vhosts how to view?

    Hi folks.  Just bought an iPad Mini, and I want to see a vhost on another computer.  The "server" is Mountain Lion with vhosts entered as alpha.local, bravo.local, pointing to proper directories in /Library/Webserver/Documents/ and entries also locat