Solved

Showing Web-Page in a Browser from Applikation ?

Posted on 1998-08-17
8
169 Views
Last Modified: 2010-03-30
How can I open a Web Page in a Browser from a Java Applikation ?
I wanna send a URL from a Java Applikation to the default Browser on the System (e.g. IE, Communicator)!
Further more I want to decide if the page will open in a new
Browser-Window or in an old one!

Thanks for helping
0
Comment
Question by:mos
  • 3
  • 2
  • 2
  • +1
8 Comments
 
LVL 6

Expert Comment

by:gadio
ID: 1220419
mos, Use the java.lang.Runtime.exec command to invoke the browser, and send the page as a parameter. About displaying a URL in a currently open browser, there is no uniform way to do that. The communicator has an interface for 'remote activation' of URLs but the Explorer mechanizem is different. In any case hooking into these interfaces may prove to be quite complicated. The exec approach is probably more cost effective.

I comment this answer so that someone may answer better regarding the displaying of URLs in a currently open brawser.

G.
0
 
LVL 2

Expert Comment

by:threshold
ID: 1220420
But how to get the "Default" browser program and it's pathname?
I think we need a native method to help us to find it out.
0
 

Author Comment

by:mos
ID: 1220421
Threshold, you are right.
I really need a way to get the "default" browser and the possibility to open pages in an old window (preventing to open hundreds of different browser windows)!
So, how does the nativ method look like on a win32 system ?

0
 
LVL 1

Accepted Solution

by:
jdyer earned 50 total points
ID: 1220422
Ok, whether or not a new window is opened by the browser on a win32 system is browser dependent. But, this WILL tell you how to open one using the default browser.

1. Load the library shell32.dll in the Windows System directory
2. Call HINSTANCE ShellExecute(
 

    HWND  hwnd,      // handle to parent window
    LPCTSTR  lpOperation,      // pointer to string that specifies operation to perform
    LPCTSTR  lpFile,      // pointer to filename or folder name string
    LPCTSTR  lpParameters,      // pointer to string that specifies executable-file parameters
    LPCTSTR  lpDirectory,      // pointer to string that specifies default directory
    INT  nShowCmd       // whether file is shown when opened
   );      
Parameters
hwnd
Specifies a parent window. This window receives any message boxes that an application produces. For example, an application may report an error by producing a message box.
lpOperation
Pointer to a null-terminated string that specifies the operation to perform. The following operation strings are valid:
 
String      Meaning

"open"      The function opens the file specified by lpFile. The file can be an executable file or a document file.Windows 95 only: The file can be a Windows 95 folder to open.
"print"      The function prints the file specified by lpFile. The file should be a document file. If the file is an executable file, the function opens the file, as if "open" had been specified.
"explore"      Windows 95 only: The function explores the folder specified by lpFile.
The lpOperation parameter can be NULL. In that case, the function opens the file specified by lpFile.
lpFile
Pointer to a null-terminated string that specifies the file to open or print. The function can open an executable file or a document file. The function can print a document file.
Windows 95 only: lpFile can point to a null-terminated string that specifies a Windows 95 folder to open or explore.
lpParameters
If lpFile specifies an executable file, lpParameters is a pointer to a null-terminated string that specifies parameters to be passed to the application.
If lpFile specifies a document file, lpParameters should be NULL.
lpDirectory
Pointer to a null-terminated string that specifies the default directory.
nShowCmd
If lpFile specifies an executable file, nShowCmd specifies how the application is to be shown when it is opened.  This parameter can be one of the following values:
 
Value      Meaning

SW_HIDE      Hides the window and activates another window.
SW_MAXIMIZE      Maximizes the specified window.
SW_MINIMIZE      Minimizes the specified window and activates the next top-level window in the Z order.
SW_RESTORE      Activates and displays the window. If the window is minimized or maximized, Windows restores it to its original size and position. An application should specify this flag when restoring a minimized window.
SW_SHOW      Activates the window and displays it in its current size and position.
SW_SHOWDEFAULT      Sets the show state based on the SW_ flag specified in the STARTUPINFO structure passed to the CreateProcess function by the program that started the application. An application should call ShowWindow with this flag to set the initial show state of its main window.
SW_SHOWMAXIMIZED      Activates the window and displays it as a maximized window.
SW_SHOWMINIMIZED      Activates the window and displays it as a minimized window.
SW_SHOWMINNOACTIVE      Displays the window as a minimized window. The active window remains active.
SW_SHOWNA      Displays the window in its current state. The active window remains active.
SW_SHOWNOACTIVATE      Displays a window in its most recent size and position. The active window remains active.
SW_SHOWNORMAL      Activates and displays a window. If the window is minimized or maximized, Windows restores it to its original size and position. An application should specify this flag when displaying the window for the first time.
If lpFile specifies a document file, nShowCmd should be zero.


SW_SHOWNORMAL = 1 and that is what you will want to use.

FOR EXAMPLE:

ShellExecute( myApp, "http://www.yahoo.com", null, null, getProperties("acl.write"), 1 );

would open up Yahoo! in the default browser, with the directory as whatever is in the properties file as acl.write. Hope this helps. Tell me if you need somemore info.

Regards,
  jdyer
0
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 
LVL 2

Expert Comment

by:threshold
ID: 1220423
If you want it to run in NT....
In NT Resource Kit, You can find the tool(RegGet.exe... i forgot the name...) to get informations from NT Registry.
So. use the Runtime.exec() to run the tool.

First, you get the HKEY_CLASSES_ROOT/.html/Content Type = NetscapeMarkup

Second, you can find HKEY_CLASSES_ROOT/MetscapeMarkup/open/command =
                     C:\PROGRA~1\Netscape\COMMUN~1\Program\netscape.exe "%1"

Then you can find the default browser to open .html file... and use Runtime.exec() to open any document with C:\....\netscape.exe

0
 
LVL 6

Expert Comment

by:gadio
ID: 1220424
[jdyer] - If the window handler is a must, than that may present a problem, since through JNI its not easy to get a HWND of the java application.
0
 
LVL 1

Expert Comment

by:jdyer
ID: 1220425
teh window handler is only the handler of the parent window. Thus, just send null, and the parent will be the desktop. How does that sound?
0
 
LVL 1

Expert Comment

by:jdyer
ID: 1220426
teh should be "the"

Sorry, so instead of above in my proposed answer, it SHOULD be

ShellExecute( null, "open", "http://www.yahoo.com", null, getProperties( "acl.write" ), 1 );

The First arg is null because we want the window's parent to be the desktop;

The Second arg is "open" because we want to open http://www.yahoo.com

The Third arg is "http://www.yahoo.com" because we want to connect to Yahoo! (this can be anything.

The Fourth arg is null because we don't want any parameters

The fifth is the current directory for the application, this can be anything really, I just chose the directory where applets can write to

The fifth is SW_SHOWNORMAL (which equals 1) because that is the type of window we want.

Hopefully that will clarify things a bit

Regards,
  jdyer
0

Featured Post

What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

Join & Write a Comment

Suggested Solutions

INTRODUCTION Working with files is a moderately common task in Java.  For most projects hard coding the file names, using parameters in configuration files, or using command-line arguments is sufficient.   However, when your application has vi…
Introduction This article is the last of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers our test design approach and then goes through a simple test case example, how …
Viewers will learn about the regular for loop in Java and how to use it. Definition: Break the for loop down into 3 parts: Syntax when using for loops: Example using a for loop:
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …

757 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now