-1

Hello..Im trying to read the HTML from a URL and I threw in yahoo.com as a test...for some reason, "n.readLine()" is coming back as NULL and the while loop fails...and ideas??

thanx

<%@ page import="java.io.*" %>
<%@ page import="java.net.*" %>
<%@ page language="java" %>
<%@ page import="trader.webservices.util.Utils" %>
<%@ page import="trader.webservices.data.UserDataVO" %>
<%@ page import="trader.webservices.data.UserInfoDAO" %>
<%@ page import="trader.aabamail.AABAmailDAO" %>
<%@ page import="trader.aabamail.OutgoingMessage" %>
<%@ page import="javax.servlet.http.HttpServletRequest" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
   "http://www.w3.org/TR/html4/loose.dtd">
 <% 
 	UserDataVO userData = null;
    
 	//String username = request.getParameter("username");
	//String password = request.getParameter("password");
	String flyRequest = request.getParameter("flyRequest");
	String email = request.getParameter("emailAdd");
 
	String domainName	= UserInfoDAO.removeHostRedirection(request.getServerName());
	
	String adminServer = request.getServerName();
	String javaAdminServer = request.getServerName();
	
	
	
	
	if (request.getServerName().equals("localhost") || request.getServerName().startsWith("199")) {
			adminServer = "cpanel.homes.com";
			javaAdminServer = "localhost:8080";
	 }
	
			userData = UserInfoDAO.getUserInfo(domainName);
			String accountName = userData.getAcctName();
	
	URL flyUrl = new URL("http://www.yahoo.com/");
	
	BufferedReader in = new BufferedReader(new InputStreamReader(flyUrl.openStream()));
	String flyerInputLine;
	
	
	while ((flyerInputLine = in.readLine()) != null)
	    System.out.println(flyerInputLine);



	in.close();

	
		
			

	//This is the body of the email
	
	
	
	
   OutgoingMessage msg = new OutgoingMessage();
   msg.setFromAddr("clarence_mims@yahoo.com");
   msg.setFromName(accountName);
   msg.setToAddr(email);
   msg.setSubject("test");
   msg.setContent(flyerInputLine);
   msg.send();
	
	
 
   
   %>
   
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title>Email Flyer</title>
   <link rel="stylesheet" type="text/css" media="screen" href="/Listings/resources/css/cp-contentwell.css" />
		<link rel="stylesheet" type="text/css" media="screen" href="/Listings/resources/css/cp-tablesort.css" />
		<!--[if IE]>
		<link rel="stylesheet" type="text/css" media="screen" href="/Listings/resources/css/cp-ie.css" />
		<![endif]-->
    </head>
    <body>
       <div id="cWell">
			<h1 class="tab4dark">Email Flyer</h1>

				<div id="msgBox2">
					<ul>
						<li>Your flyer has been sent. Thank you!<%=flyRequest%><%=flyerInputLine%>
						
						
						 </li>
					</ul>
			</div>
        </div>
	</body>
</html>
2
Contributors
1
Reply
2
Views
7 Years
Discussion Span
Last Post by kk4real
0

You need to assign flyerInputLine to something, before the while loop comes around and in.readLine() makes it null when the while loop reaches the (last line of the loop + 1).

When the while loop reaches the (last line + 1) -> flyerInputLine = in.readLine() ... well in.readLine() is null, which is why the while loop ends and why you keep getting null.

Solution: Define a string before the while loop and append the values to the string, while inside the loop:

String s = new String();
while ((flyerInputLine = in.readLine()) != null)
    s += flyerInputLine;

Edited by kk4real: removed extra code

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.