Win a copy of Node.js Design Patterns: Design and implement production-grade Node.js applications using proven patterns and techniques this week in the Server-Side JavaScript and NodeJS forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Rob Spoor
  • Tim Cooke
  • Junilu Lacar
Sheriffs:
  • Henry Wong
  • Liutauras Vilda
  • Jeanne Boyarsky
Saloon Keepers:
  • Jesse Silverman
  • Tim Holloway
  • Stephan van Hulst
  • Tim Moores
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Mikalai Zaikin
  • Piet Souris

URL Data and Format

 
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
This is my original code:

I am attempting to have the contents of a URL read and then formatted so it isn't a big jumbled mess anymore. I have already asked the user for input this is where some of my problems begin because I do not know how to make sure the URL they are giving has "http://" included within it. I have already tried to use the URLValidator to know avail. Once that's done I would like to format the URL using my format specifiers that I have learned. Could I have some assistance on this?

 
Marshal
Posts: 74059
332
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Welcome to the Ranch

I think you will be moved, since that is not a specific Java8 topic. Have you been through the Java Tutorials section? That tells you how to read things. The URL constructor will throw an Exception if you try the wrong format.
If the URL is passed as a String, you can use methods of the String class to find whether it begins with something. You can also search for regular expressions to match URLs and see whether they match your URL name.
 
Campbell Ritchie
Marshal
Posts: 74059
332
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have added code tags (always use them) to your code, and doesn't it look better.
Where does the URLValidator class come from; I can't find it in the standard Java7 API.
 
Jo Jack
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks I'm glad to be here. I have not checked out those sections yet. I've just been so stuck on this for awhile now. I'll go check them out.
 
Jo Jack
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
@Cambell I really have no idea. I have asked others for help and that's what they pointed me to when I attempted to implement it ,it just didn't work.
 
Campbell Ritchie
Marshal
Posts: 74059
332
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
What didn't work? We need more info than that.
Read the example in the tutorial link I posted earlier. Adding a few lines from that to your code printed the contents of Johnson's website successfully. Have you tried that sort of thing?

I am logging off now, myself.
 
Jo Jack
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Alright thanks for your help.
 
Sheriff
Posts: 26793
82
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I don't know if this is your question, but the easiest way to fix HTML so it isn't a horrible unreadable mess is to use one of the existing HTML prettifiers. JTidy is a Java product which does that for you, so using that would be far more practical than trying to write your own code to do it.
 
Jo Jack
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
@Paul I am trying to learn how to use my format specifiers along with printing out the contents of the URL. Just to remember if asked.
 
Paul Clapham
Sheriff
Posts: 26793
82
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Oh right, you did mention format specifiers. And yes, I agree that learning to use format specifiers shouldn't be confused with cleaning up messy HTML. Carry on then, and if you have more questions don't hesitate to drop in and ask us.
 
Destroy anything that stands in your way. Except this tiny ad:
Thread Boost feature
https://coderanch.com/t/674455/Thread-Boost-feature
reply
    Bookmark Topic Watch Topic
  • New Topic