Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

problem with newlines in my servlet

Status
Not open for further replies.

GBONGIOVANO

Programmer
Jan 17, 2003
16
0
0
US
In reference to newlines. In netscape and opera each line of my servlet prints correctly however in Internet Explorer its just one long string.
I've reloaded it, pressed enter, and even deleted the Internet files and the class file and recompiled. I have the latest Internet explorer 6 w/ sp1.
Thanks,
Here's my code

import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;

public class helloWorld extends HttpServlet {
public void doGet(HttpServletRequest request,
HttpServletResponse response)
throws ServletException, IOException {
PrintWriter out = response.getWriter();
out.println("Hello World \n");
out.println("Testing\n");
out.println("Newlines\n");
}
}
 
Are you looking at the browser screen or the raw source code when you're seeing "one long string"? The newlines should show in the source code, but not on the browser screen.

Your servlet, as it's written, is printing two newlines for each println(), so nothing needs to change there. Press SHIFT+RELOAD and restart your server, close and restart your browser, recompile your class... Otherwise I don't know what's wrong.

petey
 
Recplace your &quot;\n&quot; in your calls to &quot;println&quot; by &quot;<BR/>&quot; as <BR/> is the equivalent in HTML to a carrige return. I think this sould work. Like this :
Code:
import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;

public class helloWorld extends HttpServlet {
  public void doGet(HttpServletRequest request,
                    HttpServletResponse response)
      throws ServletException, IOException {
    PrintWriter out = response.getWriter();
    out.println(&quot;Hello World <BR/>&quot;);
    out.println(&quot;Testing<BR/>&quot;);
    out.println(&quot;Newlines<BR/>&quot;);
  }
}
Water is not bad as long as it stays out human body ;-)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top