6 Replies - 2555 Views - Last Post: 13 December 2008 - 06:27 PM Rate Topic: -----

#1 markhazlett9  Icon User is offline

  • Coding is a lifestyle
  • member icon

Reputation: 60
  • View blog
  • Posts: 1,666
  • Joined: 12-July 08

Reading HTML input from a web server

Posted 13 December 2008 - 12:59 PM

Hello Everyone,

I'm trying to read some html from some web servers but I can't seem to get it to output the way I want. It seems that it is storing all of the html for the website in 1 string and then output is then on a single line. I'm wondering if there is any way to chop it up and output it like html without breaking the string? Here is my code... it's located inside an action listener... Thanks

	public class EnterActionListener implements ActionListener
	{
		public void actionPerformed(ActionEvent event)
		{
			String Url;
			String BrowserString = "";
			
			//get the item from the text bar and store it in a string
			Url = URLBar.getText();
			
			try
			{
				URL NewUrl = new URL(Url);
				URLConnection NewConnection = NewUrl.openConnection();
				
				//check if the response is HTTP_OK
				HttpURLConnection HttpConnection = (HttpURLConnection) NewConnection;
				int ResponseCode = HttpConnection.getResponseCode();
				
				String MessageConnection = HttpConnection.getResponseMessage();
				
				Display.setText(ResponseCode + " " + MessageConnection);

				if(ResponseCode != HttpURLConnection.HTTP_OK)
				{
					return;
				}

				//read the server response
				InputStream InStream = NewConnection.getInputStream();
				Scanner Input = new Scanner(InStream);

				while(Input.hasNextLine())
				{
					String TempString="";
					
					TempString = Input.nextLine();
					
					Display.append(TempString);
				}
				
			}	
			catch(Exception e)
			{
				JOptionPane.showMessageDialog(null, "Cannot find the website" +
						" ensure that is in the format [url="http://www.google.ca/");"]http://www.google.ca/");[/url]
			}
		}
	}


Cheers :^:

Is This A Good Question/Topic? 0
  • +

Replies To: Reading HTML input from a web server

#2 Programmist  Icon User is offline

  • CTO
  • member icon

Reputation: 252
  • View blog
  • Posts: 1,833
  • Joined: 02-January 06

Re: Reading HTML input from a web server

Posted 13 December 2008 - 01:20 PM

Let me get ths straight. You want to put line breaks and tabs/spaces in the HTML. You want to change this:

<html><head><meta http-equiv="content-type" content="text/html; charset=ISO-8859-1"><title>Google</title>...


into this:

<html>
	<head>
		<meta http-equiv="content-type" content="text/html; charset=ISO-8859-1">
			<title>Google</title> ...


Correct?

If this is the case, check out JTidy.

This post has been edited by Programmist: 13 December 2008 - 01:21 PM

Was This Post Helpful? 0
  • +
  • -

#3 markhazlett9  Icon User is offline

  • Coding is a lifestyle
  • member icon

Reputation: 60
  • View blog
  • Posts: 1,666
  • Joined: 12-July 08

Re: Reading HTML input from a web server

Posted 13 December 2008 - 01:25 PM

View PostProgrammist, on 13 Dec, 2008 - 12:20 PM, said:

Let me get ths straight. You want to put line breaks and tabs/spaces in the HTML. You want to change this:

<html><head><meta http-equiv="content-type" content="text/html; charset=ISO-8859-1"><title>Google</title>...


into this:

<html>
	<head>
		<meta http-equiv="content-type" content="text/html; charset=ISO-8859-1">
			<title>Google</title> ...


Correct?

If this is the case, check out JTidy.



Ok Right on ya that's exactly what I want to do... I can't seem to find it online though on using it or in eclipse... how does the syntax go for it?
Was This Post Helpful? 0
  • +
  • -

#4 Programmist  Icon User is offline

  • CTO
  • member icon

Reputation: 252
  • View blog
  • Posts: 1,833
  • Joined: 02-January 06

Re: Reading HTML input from a web server

Posted 13 December 2008 - 01:54 PM

Check out the JTidy website. There are usage instructions there.
Was This Post Helpful? 0
  • +
  • -

#5 markhazlett9  Icon User is offline

  • Coding is a lifestyle
  • member icon

Reputation: 60
  • View blog
  • Posts: 1,666
  • Joined: 12-July 08

Re: Reading HTML input from a web server

Posted 13 December 2008 - 02:17 PM

View PostProgrammist, on 13 Dec, 2008 - 12:54 PM, said:

Check out the JTidy website. There are usage instructions there.



That does look like exactly what I'm looking for. I tried downloading, but i'm not sure where exactly to put it once it's downloaded. I'm using OS X and i'm wondering if anyone knows how to add 3rd party API's to the Library?
Was This Post Helpful? 0
  • +
  • -

#6 Programmist  Icon User is offline

  • CTO
  • member icon

Reputation: 252
  • View blog
  • Posts: 1,833
  • Joined: 02-January 06

Re: Reading HTML input from a web server

Posted 13 December 2008 - 05:51 PM

I don't use Mac, so I can't help you there, but if you're using Eclipse you should include the JAR file the same way you include any other library. Are you familiar with that? Or, even better, if you are using Maven to build your project you can use the Maven plugin for Eclipse, but I have the feeling that's probably not on the radar - am I right?
Was This Post Helpful? 0
  • +
  • -

#7 markhazlett9  Icon User is offline

  • Coding is a lifestyle
  • member icon

Reputation: 60
  • View blog
  • Posts: 1,666
  • Joined: 12-July 08

Re: Reading HTML input from a web server

Posted 13 December 2008 - 06:27 PM

View PostProgrammist, on 13 Dec, 2008 - 04:51 PM, said:

I don't use Mac, so I can't help you there, but if you're using Eclipse you should include the JAR file the same way you include any other library. Are you familiar with that? Or, even better, if you are using Maven to build your project you can use the Maven plugin for Eclipse, but I have the feeling that's probably not on the radar - am I right?



ha ha no I am not familiar with Maven, and I am using eclipse. I'm just not sure where to put the files to make sure that they include in my library import. I tried putting them into my workspace but then it said it couldn't find the library when I tried to import it so i think I have it in the wrong directory. Any ideas?
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1