Open a webpage using Java

Hi,
I am trying to open a webpage in a browser using Java code. I have been reading the tutorials and came across some code that reads the webpage as a simple text using getPageContent etc. I don't need to read the page, I just need to open it.
Can anyone please guide me, tell me which docs I should refer to etc.
Thanks,
M

import java.awt.Desktop; //Java 1.6
import java.io.IOException;
import java.net.URI;
import java.net.URISyntaxException;
public class BrowseExample {
    public static void main(String[] args) throws IOException, URISyntaxException {
        URI uri = new URI("http://java.sun.com");
        Desktop.getDesktop().browse(uri);
}

Similar Messages

  • How to open/read file using Java in Unix?

    Hi Friends,
    Can you please help me out how to open/read file using java in unix os? I have create one text file in "/home/test.txt" in unix environment. How to open the same file & read using java code?
    - Hiren Modi

    http://java.sun.com/docs/books/tutorial/essential/io/index.html

  • How to open specific port using java program

    Hello,
    I want to open ,close port using java comm.plz help me how can i do it.is it possible
    by using java program.later i want to use that specific port to accept the server socket connection .plz
    help me.

    i try this java program.*but it get block in accept method*.tht mean i m not able to make connection with port.
    import java.sql.SQLException;
    import java.io.IOException;
    import java.net.ServerSocket;
    import java.util.logging.Level;
    import java.util.logging.Logger;
    class MakeConn
         public final static int PORT = 7788;
    public static java.net.Socket clientSocket = null;
    public static java.io.PrintWriter pw = null; // socket output stream
    public static java.io.BufferedReader br = null;
    public static ServerSocket server_socket;
         public static void main(String[] args) throws SQLException
         try {
              server_socket = new ServerSocket(PORT);
    clientSocket = server_socket.accept();
    System.out.println("CLIENT>>>" + clientSocket);
         br = new java.io.BufferedReader(new java.io.InputStreamReader(clientSocket.getInputStream()));
    pw = new java.io.PrintWriter(clientSocket.getOutputStream(), true);
    String message = br.readLine().trim();
    System.out.println("message is"+message);
    pw.close(); // close everything
    br.close();
    clientSocket.close();
         catch (Exception ex) {
    ex.printStackTrace();
    }

  • Error trying to open a file using java.io.* in an Applet

    I have a file called wordlist.txt and I am using java.io.* to open it. When I try it
    in Applet Viewer it runs without a hitch. But when I try to run it in a
    browser as an Applet, it errors out saying:
    com.ms.security.SecurityExceptionEx[package3/SpellCheck.setWordList]: cannot access file wordlist.txt
    I have tried adding this file to my Project and accessing it that way but I still get
    the same message. If anyone can help with this, I sure would appreciate it.
    My code is as follows:
    String inWord = new String("zzz");
    try {
    File myWordList = new File("wordlist.txt");
    BufferedReader inWordList = new BufferedReader(
    new FileReader(myWordList));
    inWord = inWordList.readLine();
    while (inWord != null) {
    wordList.addElement(inWord);
    inWord = inWordList.readLine();
    } // end while
    inWordList.close();
    } // end try
    catch (Exception e1) {
    // Pr is equivalent System.out.println();
    Pr("Error Reading this line " + '\n' + inWord + '\n' + e1);
    } // end catch
    } // end setWordList()

    Applets are generally prevented from reading as well as writing files, but appletviewer can load files from the hard drive, so, that is the cause of the behaviour you have observed. To know more about enabling applets load files, you have to sign your applets,
    learn more at
    http://java.sun.com/sfaq/#prevent

  • How to open Word Document using java?

    Respected Sir/ Madam,
    I am doing my project in Network Security using java. I have to transfer the files from server to the client. Each transferred file should have some of the access privileges such as read, write and exeucte. If the transferred file is a word document means then automatically the client should open Microsoft word and if the file is having Read Permission alone then the save, Save As, cut,copy, paste options in the MS - Word should be disabled. This is similar for all the files that i have transferred. That is if the transferred file is excel, audio, video,txt file the corresponding application should be opened properly. How could I acheive this. If the file is having write permission then if the user clicks the save option then the contents of the file should be saved in the server machine not in the client machine, Could we achieve this???? Can anyone help me regarding this? Please give me your views about this query?

    Respected Sir / Madam,
    Thank you very much for your reply. Could we use Microsoft API inside java program to achieve my doubts?? Could U explain it more????

  • How can I open a program using Java and then perform certain tasks with it?

    For example, and this is just an example, I want to write a Java program that opens MS Paint and then manipulates that program. This can be useful to automate certain tasks.
    My question is whether this can be done writing Java code and if so how? If not possible, would I need to use a scripting language instead?

    write a Java program that opens MS Paint and then
    manipulates that program. This can be useful to
    automate certain tasks."manipulates" is a too wide term. Let me narrow down:
    1. If you want to open (run) the program and then shut (kill) it down it is possible and fairly trivial to do in java. Look up Runtime and Process classes in java.lang package
    2. If you want to open the program and edit some image/document in the opened program. It is very difficult in java. May be possible... using some Java/COM bridge, assuming your native program is COM/Active-x compliant. Note: these things go beyond the boundary of JVM and needs to interact with host OS and involves shared memory, ipc and all "low level" stuffs.
    If you want to be able to play around with these COM/Activex apps- choose .NET instead :-)
    3) You can open the program from java and pass it some command line arg as in (1) above and then the program will load that document/image at startup automatically. You may then edit the doc/image thru that program itself. However, Java is not doing anything for you here, other than just starting off your native mspaint.exe ot notepad.exe.
    -BJ
    Message was edited by:
    Bimalesh

  • Opening a webpage using url.getConnection and populating?

    Hi
    I want to write a tool that opens a webpage given the URL and populates the page with provided information and clicks the button i.e. want a tool that automates this workflow.
    I understand I can tweak with url.getConnection and get the page populated but I am clueless about populating the page automatically with the data. Is there any way to do it?
    Thanks
    Raja

    Hi
    Thanks for your immediate knowledge sharing, ya right JSP can be accessed as it resides in the server also I understand the HTML coding is more than enough for me to understand the values I need to pass to given the input type of fields with the FORM tag.
    Having understood thus far, you people mention getting the HTML code but how do I get that programatically, it is that I can load the JSP/page using URL.getConnection and open the page in the browser, one way is doing VIEW SOURCE manually and getting the code, can you educate me on how to do it programatically to view source of the displaying page on a browser?
    Thanks
    Raja

  • Open a file using java......... how?

    hi all
    I have a prob with my code
    the problem is by using the FileChooser like
    file = fileChooser.getSelectedFile();
    I have the file name but how can i open that file e.g. if file is word document then that file should open in word , if that file is HTML file then open in IE , and other files as well.
    is there any way to open a file
    plz help me
    Thanx
    Regards
    Satinderjit

    veer ji, try this code on your pc if you can. Click the print button and see that happens. thanx yuvraj:
    import java.awt.*;
    import java.awt.event.*;
    import java.awt.print.*;
    //import com.sun.java.swing.*;
    import javax.swing.*;
    public class ComponentPrinterFrame
    extends JFrame
    implements Printable {
    public static void main(String[] args) {
    ComponentPrinterFrame cpf = new ComponentPrinterFrame();
    cpf.setVisible(true);
    public ComponentPrinterFrame() {
    super("ComponentPrinterFrame v1.0");
    createUI();
    protected void createUI() {
    JPanel panel = new JPanel();
    JButton printButton = new JButton("Print");
    panel.add(printButton);
    panel.add(new JList(new Object[] { "One", "Two", "Three" }));
    panel.add(new JButton("Push me"));
    panel.add(new JCheckBox("Chess", true));
    panel.add(new JComboBox(new Object[] { "Eins", "Zwei", "Drei" }));
    printButton.addActionListener(new ActionListener() {
    public void actionPerformed(ActionEvent ae) {
    PrinterJob pj = PrinterJob.getPrinterJob();
    pj.setPrintable(ComponentPrinterFrame.this);
    if (pj.printDialog()) {
    try { pj.print(); }
    catch (PrinterException pe) {
    System.out.println(pe);
    setContentPane(panel);
    setSize(400, 400);
    // Center.
    Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
    Dimension frameSize = getSize();
    int x = (screenSize.width - frameSize.width) / 2;
    int y = (screenSize.height - frameSize.height) / 2;
    setLocation(x, y);
    addWindowListener(new WindowAdapter() {
    public void windowClosing(WindowEvent e) {
    dispose();
    System.exit(0);
    public int print(Graphics g, PageFormat pf, int pageIndex) {
    if (pageIndex != 0) return NO_SUCH_PAGE;
    Graphics2D g2 = (Graphics2D)g;
    g2.translate(pf.getImageableX(), pf.getImageableY());
    getContentPane().paint(g2);
    return PAGE_EXISTS;

  • Opening existing apps using java.awt.Desktop

    I want to display my html file using existing applications such as IE. How I can do this?
    My java version is 1.6 so the java.awt.Desktop is good for my reason?

            try {
                Desktop.getDesktop().open(new File("test.html"));
            } catch (IOException ex) {
                ex.printStackTrace();
            }

  • Opening a webpage in java

    I'm doing a project for college that generates webpages with applets embedded in them. It works fine but it's not great that the user has to go back to the folder that the program is in to find the web page.
    Is there any way to make the web pages open up straigth away when they are generated so the user doesn't have to go looking for them?
    Thanks

    If you mean that you want to automatically start browser window with the page inside here is a useful article:
    http://www.javaworld.com/javaworld/javatips/jw-javatip66.html
    HTH
    Mike

  • WHEN I OPEN ANYTHNG THAT USES JAVA FIREFOX CRASHES

    I use Firefox mainly for Tazareo.com. I have 2 screens so I have Taza open for information and adding data into that system. My problem is that I cannot download anything to taza and when I try it crashes and takes firefox with it. I have contacted Taza and they said it was not on their end. My IT guy has no clue and I really need to download and upload from my computer. My work load is increasing and I need to get this problem corrected. I know nothing about computers ( I was born about the time they were being invented) So if you could give me a step by step instructions on what might be the problem, I could hopefully fix this problem. I even went into a site that was suggested on Firefox to see if Java could troubleshoot and it crashed on that site.

    I play zynga games and flash with Firefox has slowed pc way down

  • How to disable print and download button of pdf file when i am opening mozila firefox using java script

    i am opening pdf file in firefox browser in right side i am seeing print and download option
    i want to disable it by program like javascript, by manualy i can disable it ,
    actually i am opening pdf file in my website by using firefox browser so i do not want to any can download or print the pdf file

    If it's that critical, you could explore this partial workaround:
    Use a script or configuration file on your server that changes the disposition based on the user agent. In other words, for Firefox, send an attachment disposition that forces a download outside the browser instead of the default (inline) disposition that allows Firefox to display the PDF in a tab.
    Now... that won't stop the user from dragging and dropping the downloaded file on a Firefox tab to use the built-in PDF viewer, but most users would tend to open the file in their default viewer (e.g., stand-alone Adobe Reader).

  • Upgrade to 18.0 has disabled Java even though plugin checker says Java 7 Update 10 is up to date, yet webpages using java display "missing plug in" error

    Attempting to install the "missing plug-in" using the Firefox prompts results in Java 7 Update 10 being installed, re-installing it is successful and does not resolve the issue, Firefox 18 refuses to allow/display java content even with the proper updated version of Java installed.
    This problem ONLY occurred immediately following this mornings update to Firefox 18.0.

    Context:
    Yesterday: Java working fine.
    This morning: Update to Firefox 18.0
    Java will not work, not at all even with Java 7 Update 10 installed, not even the "verify java version" applet at http://www.java.com/en/download/installed.jsp will display.
    When attempting to view/display any java content the "missing plug-in" error bar at the top of the page displays and attempting to install the required plug-in via that method does not resolve the issue even though the correct version of Java is installed and the plug-in checker verified it was "up-to-date".

  • Doing Calculations in a css webpage using java

    Hi
    I run a small website for ex members of an RAF Squadron. We would like to offer items for sale on the site but do not want to go down the route of a shopping trolly scenario where by we have to deal with electronic cash payments. To this end I have done a small page that has a table. I would like to be able to present the prospective purchaser with a total cost at the end of thier shopping trip. I was wondering if anyone could help me with the code
    i.e one field is quantity the other is total so the math is x*y simple, even this old grey hair cabn work that out but how do I make it look pretty on the site?
    I have tried to do it using jbots in frontpage , but these don't seem to like the table structure
    below is the portion of the page relating to the table. Apologies to the purists who know all the ins and outs, but I am just learning and rather late into the game.
    <style type="text/css" media="screen">
    .datatable {
         border: 1px solid #D6DDE6;
         border-collapse: collapse;
         width: 10%;
    .datatable caption {
         color: #33517A;
         font: bold 1.2em Arial, Helvetica, sans-serif;
         padding-bottom: 8px;
         padding-top: 3px;
         text-align: left;
    .datatable td {
         border: 1px solid #D6DDE6;
         padding: 4px;
    .datatable th {
         background-color: #BCBCBC;
         border: 1px solid #828282;
         color: Navy;
         font: sans-serif;
         font-style: italic;
         text-align: center;
         font-weight: bold;
         padding-left: 4px;
    .datatable tr.altrow {
         background-color: #FFFFBB;
         color: Navy;
         font: sans-serif;
         font-style: oblique;
         text-align: justify;
         font-weight: bold;
         padding-left: 4px;
    </style>
    </head><body>
    <img src="images/sqnshop.jpg" style="margin-left: 10em;" />
    <h1 style="color: #0002DD; text-align: center;">Welcome to the 202 Squadron Shop</h1>
    <div id="side1">
    <h3>Navigation</h3>
    <ul>
         <li><a href="Home Page</li>
         <li><a href="Squadron History</li>
         <li><a href="Association Scrapbook</li>
         <li>The Line Book</li>
         <li>The Mucky Duck</li>
         <li>Members Directory</li>
         <li><a href="Requests For Assistance</li>
         <li><a href="Constitution & Committee</li>
    <li>Links To Friends & Associates</li>
         </ul>     
         </div>
    <div id="content">
    <p style="text-align: center;">With the exception of any items marked "Squadron Only", these items are offered for sale to all visitors to the site.</p>
    <p style="font-family: Verdana, Arial, sans-serif; font-size: 0.6em; color: Black;">Please Note: These items are offered by kind permission of the Officer Commanding 202 Squadron. The Squadron do not undertake on line payments. All transactions must be by a cheque for the correct amount in sterling and encashable at a UK bank. Goods will not be sent until confirmation that the cheque has cleared and the requisite funds are deposited in their account. There will be no relaxation of these rules</p>
         <form method="post" action="action="http://www/">
         <table summary="202 Squadron Shop Price List" class="datatable" style="font-family: Verdana, Arial, sans-serif; font-size: 1em; ">
              <tr>
              <th scope="col">Item</th>
              <th scope="col">Item Cost</th>
              <th scope="col">Qty Req'd</th>
              <th scope="col">Total Item Cost</th>
              </tr>
              <tr class="altrow" style="font-family: Verdana, Arial, sans-serif; font-size: 0.7em;">
              <td>Engraved Sqn Tankard</td><td>�16.00</td><td><span><label for="tankard"></label><input type="text" name="tankard" id="tankard" size="3" style="font-family: Arial; font-size: 1em; font-weight: bold" /></span></td><td><span><label for="tankcost"></label><input type="text" name="tankcost" id="tankcost" size="3" style="font-family: Arial; font-size: 1em; font-weight: bold" /></span></td></tr><tr class="altrow" style="font-family: Verdana, Arial, sans-serif; font-size: 0.7em;"><td>Squadron Tie</td><td>�6.00</td><td><span><label for="tie"></label><input type="text" name="tie" id="tie" size="3" style="font-family: Arial; font-size: 1em; font-weight: bold" /></span></td>
         <td><span><label for="tiecost"></label><input type="text" name="tiecost" id="tiecost" size="3" style="font-family: Arial; font-size: 1em; font-weight: bold" /></span></td></tr>
         <tr class="altrow" style="font-family: Verdana, Arial, sans-serif; font-size: 0.7em;"><td>Sqn Plaque</td><td>�21.00</td><td><span><label for="plaque"></label><input type="text" name="plaque" id="plaque" size="3" style="font-family: Arial; font-size: 1em; font-weight: bold" /></span></td><td><span><label for="plaquecost"></label><input type="text" name="plaquecost" id="plaquecost" size="3" style="font-family: Arial; font-size: 1em; font-weight: bold" /></span></td></tr>
         <tr class="altrow" style="font-family: Verdana, Arial, sans-serif; font-size: 0.7em;"><td>Squadron Cummerbund</td><td>�20.00</td><td><span><label for="cummerb"></label><input type="text" name="cummerb" id="cummerb" size="3" style="font-family: Arial; font-size: 1em; font-weight: bold" /></span></td>
         <td><span><label for="cummerbcost"></label><input type="text" name="cummerbcost" id="cummerbcost" size="3" style="font-family: Arial; font-size: 1em; font-weight: bold" /></span></td></tr><tr class="altrow" style="font-family: Verdana, Arial, sans-serif; font-size: 0.7em;"><td>Sqn Print</td><td>�7.50</td>
         <td><span><label for="sqnprint"></label><input type="text" name="sqnprint" id="sqnprint" size="3" style="font-family: Arial; font-size: 1em; font-weight: bold" /></span></td>
         <td><span><label for="printcost"></label><input type="text" name="printcost" id="printcost" size="3" style="font-family: Arial; font-size: 1em; font-weight: bold" /></span></td></tr>
         <tr class="altrow" style="font-family: Verdana, Arial, sans-serif; font-size: 0.7em;"><td>Squadron Cufflinks</td><td>�6.00</td><td><span><label for="cufflinks"></label><input type="text" name="cufflinks" id="cufflinks" size="3" style="font-family: Arial; font-size: 1em; font-weight: bold" /></span></td>
         <td><span><label for="cuffcosts"></label><input type="text" name="cuffcost" id="cuffcost" size="3" style="font-family: Arial; font-size: 1em; font-weight: bold" /></span></td></tr><tr class="altrow" style="font-family: Verdana, Arial, sans-serif; font-size: 0.7em;"><td>Squadron Tiepins</td><td>�4.00</td>
         <td><span><label for="tiepins"></label><input type="text" name="tiepins" id="tiepins" size="3" style="font-family: Arial; font-size: 1em; font-weight: bold" /></span></td>
         <td><span><label for="tiepincosts"></label><input type="text" name="tiepincosts" id="tiepincosts" size="3" style="font-family: Arial; font-size: 1em; font-weight: bold" /></span></td></tr>
         <tr class="altrow" style="font-family: Verdana, Arial, sans-serif; font-size: 0.7em;"><td>Bookmark (Photo & Sqn history)</td><td>�1.00</td><td><span><label for="bookmark"></label><input type="text" name="bookmark" id="bookmark" size="3" style="font-family: Arial; font-size: 1em; font-weight: bold" /></span></td><td><span><label for="bookmarkcosts"></label><input type="text" name="bookmarkcosts" id="bookmarkcosts" size="3" style="font-family: Arial; font-size: 1em; font-weight: bold" /></span></td></tr>
         <tr class="altrow" style="font-family: Verdana, Arial, sans-serif; font-size: 0.7em;"><td>Sea King Postcard</td><td>�0.25</td><td><span><label for="postcard"></label><input type="text" name="postcard" id="postcard" size="3" style="font-family: Arial; font-size: 1em; font-weight: bold" /></span></td><td><span><label for="postcardcosts"></label><input type="text" name="postcardcosts" id="postcardcosts" size="3" style="font-family: Arial; font-size: 1em; font-weight: bold" /></span></td></tr>
         <tr class="altrow" style="font-family: Verdana, Arial, sans-serif; font-size: 0.7em;">
         <td>Total Unit Cost</td><td></td><td></td><td><span><label for="totalcostscosts"></label><input type="text" name="totalcosts" id="totalcosts" size="3" style="font-family: Arial; font-size: 1em; font-weight: bold" /></span>
         </td></tr><tr class="altrow" style="font-family: Verdana, Arial, sans-serif; font-size: 0.7em;"><td>Postage & Packing</td><td></td><td></td>
         <td><span><label for="postandpack"></label><input type="text" name="postandpack" id="postandpack" size="3" style="font-family: Arial; font-size: 1em; font-weight: bold" /></span></td></tr><tr class="altrow" style="font-family: Verdana, Arial, sans-serif; font-size: 0.7em;"><td>Amount Due</td><td></td><td></td><td><span><label for="amount_due"></label><input type="text" name="amount_due" id="amount_due" size="3" style="font-family: Arial; font-size: 1em; font-weight: bold" /></span></td></tr>
         <p><label for="Forename">Please enter your first name: </label><input type="text" name="Forename" id="Forename" size="25" style="font-family: Verdana,Arial,sans-serif; font-size: 0.8em; font-weight: bold;" /><br /></p>
         <p><label for="Surname">Please enter your surname: </label><input type="text" name="surname" id="surname" size="25" style="font-family: Verdana,Arial,sans-serif; font-size: 0.8em; font-weight: bold" /></p>
         <p><label for="email_address">Please enter your e-mail address: </label><input type="text" name="email" id="email_address" size="80" style="font-family: Verdana,Arial,sans-serif; font-size: 0.8em; font-weight: bold" /></p>
         <input type="hidden" name="subject" value="202 Squadron Giftshop Order" />
         <input type="hidden" name="required" value="email,surname " />
         <input type="hidden" name="redirect" value="http://www" />
         <input class="green" type="submit" value="Send Order"/> <input class="red" type="reset" value="Cancel Order"/>
         </form>
         </div>
    <div id="side2">
    <h3></h3>
    </div>
    </body>
    </html>
    Any suggestions will be gratefully received
    Cheers
    Mike

    Seems to me your question is about Javascript. At least, that is how you would get calculations done in a web page (CSS has nothing to do with that). However this forum is about Java, which is a completely different language.
    You'll find a Javascript forum here:
    http://saloon.javaranch.com/cgi-bin/ubb/ultimatebb.cgi

  • Open new window using java code and not in script

    i need some method like sendredirect or forward . where i can make some codes so as to open a new window.
    actually i am calling a jsp from one jsp file where a lot of dynamic parameters are sent. and in the second jsp i call a servlet which works to download a file to the client side. i want the file should open in new window not in the browser from where it is initiated.
    else can any one say the mime type where i can open file(a xls file) in xls window and not in browser which is not needed as user needs to press the back button(present in browser)

    Hi,
    in your code
    the following code, which is used to set the file name that is to be downloded
    response.setHeader("Content-Disposition", "*inline*; filename=somename.xls" );
    to be replaced by
    response.setHeader("Content-Disposition", "*attachment*; filename=somename.xls" );
    it will work fine try it.
    Edited by: Bhaskar.krishna on Jan 17, 2008 12:56 AM

Maybe you are looking for

  • Install windows 8.1 in 10.9 Mac Pro Mid 2013

    Hey guys I am trying to install windows 8.1 using ISO in CD ROM, boot camp says "Windows 8.1 cant be installed". Here is the info.pst. A post said to change the msb to  one lower mode where windows 8.1 is  but there is no windows 8.1 only windows 7.

  • Build EJB Archive unsuccessfull

    I was just trying my hand at Module programming and thought i wud start off with "Step by step guide to develop a module for reading file name in a sender file adapter" by Krishnakumar Ramamoorthy. Seems alls done but the problem is when i try to cre

  • Error message -1426 when trying to update iphone

    when i connect my phone i get a message error -1426 and it will not finish sync with itunes my phone works but no wifi and no e-mail and no ipod and then it says file not found and prompts me to restore from a backup. Any help would be great. Thanks

  • How vulnerable is my system preferences?

    I just upgraded to 10.3.9 from 10.3.8. I noticed that if I lock a system preference pane (little lock in lower left corner), it will be unlocked the next time I boot my computer or do a restart. Is this normal? My concern is with the System Preferenc

  • Zen Firmware wishl

    Ok I just got the new Zen yesterday which I absolutely love.So I decided to make my own little firmware wishlist.You can add to it if you want and I'll edit my thread. I realize some are more realistic than others, but they are all possible. I have t