open a browser and click on URL

Posted on 2005-04-17
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 .

Question by:krelmanamit
    LVL 25

    Expert Comment

    Rather than clicking on the link, can't you just pass the link to your browser?
    LVL 1

    Expert Comment

    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.

    LVL 15

    Expert Comment

    Not sure what you are looking for.
    If you want to activate a browser (like explorer) from a java program then you can do:
    If you want to activate the servlet and do not need a visual response then you can do:
    new URL("").openConnection(); -> e.g.
    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 ->
    or you can use for that httpunit ->
    If you are looking for a tool that can submit many requests to your servlets then you
    can look at jmeter ->
    LVL 30

    Accepted Solution

    >> 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....

    Author Comment

    Hi All,
    Thanks for the answers
    I maybe didn't clear my self
    new URL("").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 ?

    LVL 15

    Assisted Solution

    LVL 15

    Expert Comment

    Before 1.5 you will need to use system properties (which will have global effect):<value in milliseconds>
    and<value in milliseconds>

    Featured Post

    How to improve team productivity

    Quip adds documents, spreadsheets, and tasklists to your Slack experience
    - Elevate ideas to Quip docs
    - Share Quip docs in Slack
    - Get notified of changes to your docs
    - Available on iOS/Android/Desktop/Web
    - Online/Offline

    Join & Write a Comment

    Suggested Solutions

    Title # Comments Views Activity
    nested interface 5 29
    Issues installing SSL certificate into Apache Tomcat 3 48
    changePi Challenge 15 56
    allStar challenge 1 27
    For customizing the look of your lightweight component and making it look opaque like it was made of plastic.  This tip assumes your component to be of rectangular shape and completely opaque.   (CODE)
    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…
    Viewers will learn about the different types of variables in Java and how to declare them. Decide the type of variable desired: Put the keyword corresponding to the type of variable in front of the variable name: Use the equal sign to assign a v…
    This theoretical tutorial explains exceptions, reasons for exceptions, different categories of exception and exception hierarchy.

    730 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

    15 Experts available now in Live!

    Get 1:1 Help Now