The Artima Developer Community
Sponsored Link

Java Answers Forum
URLConnection vs. HttpURLConnection

3 replies on 1 page. Most recent reply: Apr 20, 2002 6:24 PM by Charles Bell

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 3 replies on 1 page
Hiran

Posts: 41
Nickname: jclu
Registered: Mar, 2002

URLConnection vs. HttpURLConnection Posted: Apr 15, 2002 1:06 PM
Reply to this message Reply
Advertisement
If I want to create a mini-browser (that only allows you to view web pages, as well as fill out forms on pages), should I use URLConnection or HttpURLConnection? It looks like I can do most (if not all) of what I want to do with URLConnection. But I'm not so sure.
Hiran


nagu

Posts: 7
Nickname: nagu
Registered: Apr, 2002

Re: URLConnection vs. HttpURLConnection Posted: Apr 20, 2002 1:36 AM
Reply to this message Reply
Though u use URLConnection.getCoonection(); the returned object internally is HttpURLConnection only.
i feel u can try with URLConnection.

Charles Bell

Posts: 519
Nickname: charles
Registered: Feb, 2002

Re: URLConnection vs. HttpURLConnection Posted: Apr 20, 2002 6:21 PM
Reply to this message Reply

/* SimpleWebPageReader.java
* @author: Charles Bell
* @version January 15 2001
*/

import java.awt.*;
import java.io.*;
import java.net.*;

import javax.swing.*;
import javax.swing.event.*;
import javax.swing.text.*;


public class SimpleWebPageReader implements HyperlinkListener{

JEditorPane editorpane;

public static void main(String[] args){
SimpleWebPageReader webreader = new SimpleWebPageReader();
if (args.length == 1){
webreader.show(args[0]);
}else{
webreader.show("http://www.quantumhyperspace.com/");
}
}

public void show(String urlstring){

editorpane = new JEditorPane();
editorpane.addHyperlinkListener(this);
JFrame frame = new JFrame(urlstring);
JScrollPane scrollpane = new JScrollPane(editorpane);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setContentPane(scrollpane);
frame.setSize(Toolkit.getDefaultToolkit().getScreenSize());
frame.show();

try{
editorpane.setPage(urlstring);
editorpane.setContentType("text/html");
editorpane.setEditable(false);

}catch(MalformedURLException murle){
editorpane.setContentType("text/html");
editorpane.setText("<html><body>MalformedURLException: " + murle.getMessage() + "<br>Malformed URL: Can not load url: " + urlstring + "</body></html>");;
}catch(IOException ioe){
editorpane.setContentType("text/html");
editorpane.setText("<html><body>IOException: " + ioe.getMessage() + "<br>Could not load url: " + urlstring + "</body></html>");;
}
}

public void hyperlinkUpdate(HyperlinkEvent hyperlinkevent){
HyperlinkEvent.EventType eventtype = hyperlinkevent.getEventType();
URL url = null;
if (eventtype == HyperlinkEvent.EventType.ACTIVATED){
try{
url = hyperlinkevent.getURL();
editorpane.setPage(url);
}catch(MalformedURLException murle){
editorpane.setContentType("text/html");
editorpane.setText("<html><body>MalformedURLException: " + murle.getMessage() + "<br>Malformed URL: Can not load url: " + url.toExternalForm() + "</body></html>");;
}catch(IOException ioe){
editorpane.setContentType("text/html");
editorpane.setText("<html><body>IOException: " + ioe.getMessage() + "<br>Could not load url: " + url.toExternalForm() + "</body></html>");;
}

}
}
}

Charles Bell

Posts: 519
Nickname: charles
Registered: Feb, 2002

Re: URLConnection vs. HttpURLConnection Posted: Apr 20, 2002 6:24 PM
Reply to this message Reply
Hello, I used that SimpleWebPageReader I just posted to navigate to the web site I am building using jsp's and used to it to fill out an email form and sent myself an email message.

It's simple and does the job.

Flat View: This topic has 3 replies on 1 page
Topic: lightless line Previous Topic   Next Topic Topic: Testing the Forum

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use