Open Web Browser and pass URL with Query string

S

sanjeev.atvankar

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
(e-mail address removed)
 
A

Andrew Thompson

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>

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

Message posted via JavaKB.com
http://www.javakb.com/Uwe/Forums.aspx/java-general/200710/1
 
S

Sabine Dinis Blochberger

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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,770
Messages
2,569,583
Members
45,073
Latest member
DarinCeden

Latest Threads

Top