Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Loading HTML into a Servlet

 
Richard Scothern
Ranch Hand
Posts: 83
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
I am writing a servlet that will parse HTML code. I would like the servlet to retrieve an HTML page that is given as a parameter in the GET request. Does anyone know the easiest way to do this.
Thanks,
Richard
 
Tony Alicea
Desperado
Sheriff
Posts: 3226
5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
How about opening the file using the File class to represent it, and then reading it with a BufferedReader and then parsing it?
 
Kris Nelson
Ranch Hand
Posts: 35
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Although I could be wrong, but I thought the java.io.File class handled files on a local machine and the java.net.URL class handled files across a network (i.e. Internet). I have used the java.io.File class in JavaServer Pages and Servlets for files on my server only, but I don't think it worked when I tried to instaniate them as follows:
File f = new File( "http://www.webnelly.com/includes/index_main.htm" );
I thought which class you used was dependant on whose files you were looking at (which wasn't specified in the orignal post). Please correct me if I've said anything in error (which has been known to happen).

------------------
WebNelly.com
Java/XML Web Development
Check it out!
http://www.webnelly.com
 
Richard Scothern
Ranch Hand
Posts: 83
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Actually I figured out an easier way, by using the URLConnection class.
thanks anyway
richard
 
Tony Alicea
Desperado
Sheriff
Posts: 3226
5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I didn't know where the HTML file was; in the client or in the server?
It helps to know...
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic