?
Solved

open a browser and click on URL

Posted on 2005-04-17
9
Medium Priority
?
259 Views
Last Modified: 2010-03-31
Hi all,


I have servlet in one side and I always opening a browser and click the URL and close the browser
can I write a java main that do this job.

It is important to me that if the servlet is down the program will not be stuck .

Thanks,
0
Comment
Question by:krelmanamit
7 Comments
 
LVL 25

Expert Comment

by:InteractiveMind
ID: 13801580
Rather than clicking on the link, can't you just pass the link to your browser?
0
 
LVL 1

Expert Comment

by:Tag_Markman
ID: 13802761
I agree. If possible go directly to the page. That being said sometime you don't know what location 'button' is going to be ahead of time. ex: randomize button, dynamic redirect, etc.

If this is the case, then you need to first parse the contents of the page to get the form submission location of the button and any parameters you might send it. Once you have that data, then you can point to the new location in your code.

Don't get caught up with the visuals of the web page, think in terms of the html code being sent to you by the server.

0
 
LVL 15

Expert Comment

by:aozarov
ID: 13803451
Not sure what you are looking for.
If you want to activate a browser (like explorer) from a java program then you can do:
Runtime.getRuntime().exec("explorer http://www.google.com");
If you want to activate the servlet and do not need a visual response then you can do:
new URL("http://www.google.com").openConnection(); -> e.g. http://javaalmanac.com/egs/java.net/GetHeaders.html
If you want to do the above but to be able to parse the response and extract data then you
can use either the java support for it via HTMLEditorKit -> http://javaalmanac.com/egs/javax.swing.text.html/GetLinks.html
http://javaalmanac.com/egs/javax.swing.text.html/GetText.html
or you can use for that httpunit -> http://httpunit.sourceforge.net/
If you are looking for a tool that can submit many requests to your servlets then you
can look at jmeter -> http://jakarta.apache.org/jmeter/
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
LVL 30

Accepted Solution

by:
Mayank S earned 100 total points
ID: 13803733
>> I have servlet in one side and I always opening a browser and click the URL and close the browser
>> can I write a java main that do this job.

A servlet is a web-server side component. Your client might not have a JVM installed at all. If your client clicks on a link on the web-page downloaded at his end, it would obviously open in either the same or a different browser window. But when you say that you want to do this in a main (), where would that run? Then you're talking about a Java application at the client.... not a web-server hosted servlet or something....
0
 

Author Comment

by:krelmanamit
ID: 13803872
Hi All,
Thanks for the answers
I maybe didn't clear my self
new URL("http://www.google.com").openConnection(); is the solution I need
but I read about it and when there are a problem in the connection the program as been stuck.

there are and timeout options ? or http ? something better ?

Thanks
0
 
LVL 15

Assisted Solution

by:aozarov
aozarov earned 100 total points
ID: 13803902
0
 
LVL 15

Expert Comment

by:aozarov
ID: 13803913
Before 1.5 you will need to use system properties (which will have global effect):
-Dsun.net.client.defaultConnectTimeout=<value in milliseconds>
and
-Dsun.net.client.defaultReadTimeout=<value in milliseconds>
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction Java can be integrated with native programs using an interface called JNI(Java Native Interface). Native programs are programs which can directly run on the processor. JNI is simply a naming and calling convention so that the JVM (Java…
Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
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:
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.
Suggested Courses
Course of the Month14 days, 22 hours left to enroll

839 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