This week's book giveaway is in the OCMJEA forum.
We're giving away four copies of OCM Java EE 6 Enterprise Architect Exam Guide and have Paul Allen & Joseph Bambara on-line!
See this thread for details.
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


Win a copy of OCM Java EE 6 Enterprise Architect Exam Guide this week in the OCMJEA forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "Copying html web page to servlet" Watch "Copying html web page to servlet" New topic
Author

Copying html web page to servlet

sriman roop
Greenhorn

Joined: Mar 02, 2013
Posts: 13

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


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

Joined: Jul 29, 2008
Posts: 3060
    
  38

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
Greenhorn

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: http://aspose.com/file-tools
 
subject: Copying html web page to servlet