File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Servlets and the fly likes Copying html web page to servlet Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "Copying html web page to servlet" Watch "Copying html web page to servlet" New topic

Copying html web page to servlet

sriman roop

Joined: Mar 02, 2013
Posts: 13

The servlet program below is to display the html webpage through servlet.

The servlet code above displaying null. Wats the error in the above code?
Devaka Cooray
ExamLab Creator

Joined: Jul 29, 2008
Posts: 3927

The while loop in your code has already fetched out the whole content and reached the end of the page. Attempting to read another line after the end gives null. As a solution, remove that System.out.println line and append each inputLine to a StringBuilder. Each time the loop completes, your StringBuilder instance has the whole content.

Author of ExamLab ExamLab - a free SCJP / OCPJP exam simulator
What would SCJP exam questions look like? -- Home -- Twitter -- How to Ask a Question
Sai Prasad Sabeson

Joined: Oct 10, 2011
Posts: 4
below line no 40,
put "out.println(in.readLine());"
Line no 44 to 51 is not required .
This will work seamlessly.
I agree. Here's the link:
subject: Copying html web page to servlet
It's not a secret anymore!