Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / General / October 2007

Tip: Looking for answers? Try searching our database.

Open Web Browser and pass URL with Query string

Thread view: 
sanjeev.atvankar@gmail.com - 16 Oct 2007 10:41 GMT
Hi Gurus,

I develop console application that Open Web Browser and pass URL with
query string.
My code is as below:

public static void main(String[] args)
{
 try
 {
    String command = "cmd /c start "+
                                "http://localhost:8084/NCC/Banking?"+
                                "CTRL_CODE=GetAudFile&"+
                                "zipcode=10001&file=A" ;
    System.out.println("URL is :"+command);
    Runtime.getRuntime().exec(command);
    return;
 }
 catch (Exception e)
 {
    System.out.println("Error :: "+e);
 }
}

When i run this code it opens the required URL but it doesn't take the
query string i.e. zipcode and file.

i.e. when debug the programmer i able to get the value for CTRL_CODE
but cann't able to get value(null) for zipcode and file in servlet.

Could anyone help me?

Thanks in Advance
Sanjeev
sanjeev.atvankar@gmail.com
Andrew Thompson - 16 Oct 2007 11:15 GMT
...
>I develop console application that Open Web Browser and pass URL with
>query string.
>My code is as below:
...
This few lines of code is a very fragile way to try and find the
default browser - there are probably better alternatives.

JWS BasicService.showDocument(URL)
Applet AppletContext.showDocument(URL)
pre 1.6 Desktop application BrowserLauncher2
1.6+ Desktop.browse(URI)

As an aside - I put the couple of lines of the URL
and params together through the JWS showDocument
method* and it retained the params.  Of course it was
a 404 here - but that is not the point.

Note that web start is not suited to pure console
applications, so I expect you will be better looking
to Desktop.getDesktop().browse().

OTOH, opening a browser from within a console app.
seems a little suspicious in the first place..

Is this code expected to work in a 'headless' environment?
(Something like a server that supports *no* GUIs at all).

* <http://www.physci.org/jws/#bs>
<http://www.physci.org/jws/basicserv.jnlp>

Signature

Andrew Thompson
http://www.athompson.info/andrew/

Sabine Dinis Blochberger - 17 Oct 2007 11:29 GMT
> Hi Gurus,
>
> I develop console application that Open Web Browser and pass URL with
> query string.

I use java.awt.Desktop in my Application, it might be a more independent
approach.

private void lblURLMouseClicked(java.awt.event.MouseEvent evt) {        
   // open browser with url
   // Before more Desktop API is used, first check
   // whether the API is supported by this particular
   // virtual machine (VM) on this particular host.
   if (Desktop.isDesktopSupported()) {
       Desktop desktop = Desktop.getDesktop();
       try {
           desktop.browse(URI.create(lblURL.getText()));
       } catch (IOException ex) {
           ex.printStackTrace();
       }
   }
}

Hope it helps any.
Signature

Sabine Dinis Blochberger

Op3racional
www.op3racional.eu



Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.