954,541 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

My doubt

How to call a yahoo web page in java ...

vinu_07
Newbie Poster
4 posts since Jul 2007
Reputation Points: 10
Solved Threads: 0
 

This should work on Windows

public class LoadURL
{
    private String url = "www.yahoo.com";
    
    public LoadURL(){
        
        try{        
                Runtime.getRuntime().exec
                    ("rundll32 url.dll, FileProtocolHandler " + url);    
        }
        catch(Exception e){    }
    }
    
    public static void main(String[] args){
        LoadURL load = new LoadURL();
    }
}
Cerberus
Junior Poster
162 posts since Sep 2006
Reputation Points: 27
Solved Threads: 14
 

This is another option showed in Java How to Program book. This shows you that you can build your own internet browser if you wish to do so. You can search internet for even more examples....

// Fig. 24.4: ReadServerFileTest.java
// Create and start a ReadServerFile.
import javax.swing.JFrame;

public class ReadServerFileTest
{
   public static void main( String args[] )
   {
      ReadServerFile application = new ReadServerFile();
      application.setDefaultCloseOperation( JFrame.EXIT_ON_CLOSE );
   } // end main
} // end class ReadServerFileTest
// Fig. 24.3: ReadServerFile.java
// Use a JEditorPane to display the contents of a file on a Web server.
import java.awt.BorderLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.IOException;
import javax.swing.JEditorPane;
import javax.swing.JFrame;
import javax.swing.JOptionPane;
import javax.swing.JScrollPane;
import javax.swing.JTextField;
import javax.swing.event.HyperlinkEvent;
import javax.swing.event.HyperlinkListener;

public class ReadServerFile extends JFrame 
{
   private JTextField enterField; // JTextField to enter site name
   private JEditorPane contentsArea; // to display Web site

   // set up GUI
   public ReadServerFile()
   {
      super( "Simple Web Browser" );

      // create enterField and register its listener
      enterField = new JTextField( "Enter file URL here" );
      enterField.addActionListener(
         new ActionListener() 
         {
            // get document specified by user
            public void actionPerformed( ActionEvent event )
            {
               getThePage( event.getActionCommand() );
            } // end method actionPerformed
         } // end inner class
      ); // end call to addActionListener

      add( enterField, BorderLayout.NORTH );

      contentsArea = new JEditorPane(); // create contentsArea
      contentsArea.setEditable( false );
      contentsArea.addHyperlinkListener(
         new HyperlinkListener() 
         {
            // if user clicked hyperlink, go to specified page
            public void hyperlinkUpdate( HyperlinkEvent event )
            {
               if ( event.getEventType() == 
                    HyperlinkEvent.EventType.ACTIVATED )
                  getThePage( event.getURL().toString() );
            } // end method hyperlinkUpdate
         } // end inner class
      ); // end call to addHyperlinkListener

      add( new JScrollPane( contentsArea ), BorderLayout.CENTER );
      setSize( 400, 300 ); // set size of window
      setVisible( true ); // show window
   } // end ReadServerFile constructor

   // load document
   private void getThePage( String location )
   {
      try // load document and display location 
      {
         contentsArea.setPage( location ); // set the page
         enterField.setText( location ); // set the text
      } // end try
      catch ( IOException ioException ) 
      {
         JOptionPane.showMessageDialog( this,
            "Error retrieving specified URL", "Bad URL", 
            JOptionPane.ERROR_MESSAGE );
      } // end catch
   } // end method getThePage
} // end class ReadServerFile
peter_budo
Code tags enforcer
Moderator
15,436 posts since Dec 2004
Reputation Points: 2,806
Solved Threads: 902
 

Peter i compiled ur code but while running its telling some error can u locate wat it is .I dont know.


C:\Program Files\Java\jdk1.5.0\bin>javac ReadServerFile.java

C:\Program Files\Java\jdk1.5.0\bin>java ReadServerFile
Exception in thread "main" java.lang.NoSuchMethodError: main

C:\Program Files\Java\jdk1.5.0\bin>

while running cerberus code its showin that LoadUrl is public should be declared in a file named LOADURL.java compliation error

vinu_07
Newbie Poster
4 posts since Jul 2007
Reputation Points: 10
Solved Threads: 0
 

It just means that because of the 'public' keyword the filename must match the classname.

Cerberus
Junior Poster
162 posts since Sep 2006
Reputation Points: 27
Solved Threads: 14
 

Ya ur right cerberus now its running so is it possible to pass text to tat yahoo search page ...I mean to the text box in yahoo page to search ...How to do tat ???

vinu_07
Newbie Poster
4 posts since Jul 2007
Reputation Points: 10
Solved Threads: 0
 

Peter i compiled ur code but while running its telling some error can u locate wat it is .I dont know.

C:\Program Files\Java\jdk1.5.0\bin>javac ReadServerFile.java

C:\Program Files\Java\jdk1.5.0\bin>java ReadServerFile Exception in thread "main" java.lang.NoSuchMethodError: main

C:\Program Files\Java\jdk1.5.0\bin>


Because you try to run wrong class. Does ReadServerFile contain main method? No, ReadServerFileTest has main method and that is what you been supposed be runnig...

peter_budo
Code tags enforcer
Moderator
15,436 posts since Dec 2004
Reputation Points: 2,806
Solved Threads: 902
 

Is there any way to pass query to the yahoo page in java...I saw in one site tat yahoo will not support for automated queries....

vinu_07
Newbie Poster
4 posts since Jul 2007
Reputation Points: 10
Solved Threads: 0
 

If you want to interact with the Yahoo server, you will need to use HTTP over sockets. There are many tutorials for this available online, including this one from Sun:
http://java.sun.com/docs/books/tutorial/networking/index.html

Ezzaral
Posting Genius
Moderator
15,986 posts since May 2007
Reputation Points: 3,250
Solved Threads: 847
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You