Servlet output in IE

Discussion in 'Java' started by Sameer, Jun 8, 2006.

  1. Sameer

    Sameer Guest

    Hello,
    I have the following servlet 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("Hello World\n");
    out.println("Hello World\n");
    out.println("Hello World\n");
    }
    }

    The first time I execute the servlet, it gives me the output:
    Hello World Hello World Hello World Hello World
    i.e. all the text in a single line.
    Please note that no HTML code is embedded in the servlet.

    The next time I refresh the same page, the output is:


    Hello World

    Hello World

    Hello World

    Hello World

    Why this may be happening?
    Please clarify.
     
    Sameer, Jun 8, 2006
    #1
    1. Advertising

  2. Sameer wrote:
    >
    > The first time I execute the servlet, it gives me the output:
    > Hello World Hello World Hello World Hello World
    > i.e. all the text in a single line.
    > Please note that no HTML code is embedded in the servlet.
    >
    > The next time I refresh the same page, the output is:
    >
    >
    > Hello World
    >
    > Hello World
    >
    > Hello World
    >
    > Hello World
    >
    > Why this may be happening?
    > Please clarify.


    what you have to look at is not only what you put in your response, but
    also how the browser interprets it. To know that you can look at the
    content type. If you don't set the content type I believe there is no
    content type header sent to the client, which makes explorer free to
    interpret it.
    The fact that you see it in different ways is probably a bug, I assume
    related to the fact that the second time the file is probably read from
    the cache.
     
    Andrea Desole, Jun 8, 2006
    #2
    1. Advertising

  3. Sameer

    asaguden Guest

    I agree with Andrea. but I have a tip, try the same with Firefox.
    And turn off your web site cache.

    ( IE ususally assumes whats coming is HTML, but Firefox doesnt.
    Which means that if you dont specify the output there will be a
    difference )

    / Peter
    Sameer wrote:
    > Hello,
    > I have the following servlet 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("Hello World\n");
    > out.println("Hello World\n");
    > out.println("Hello World\n");
    > }
    > }
    >
    > The first time I execute the servlet, it gives me the output:
    > Hello World Hello World Hello World Hello World
    > i.e. all the text in a single line.
    > Please note that no HTML code is embedded in the servlet.
    >
    > The next time I refresh the same page, the output is:
    >
    >
    > Hello World
    >
    > Hello World
    >
    > Hello World
    >
    > Hello World
    >
    > Why this may be happening?
    > Please clarify.
     
    asaguden, Jun 8, 2006
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Andy Fish
    Replies:
    4
    Views:
    2,420
    Andy Fish
    Dec 17, 2003
  2. Sean Clarke
    Replies:
    1
    Views:
    1,900
    Sudsy
    Jan 7, 2004
  3. circuit_breaker
    Replies:
    2
    Views:
    2,013
    Jack Jia
    Apr 4, 2004
  4. chamikara
    Replies:
    1
    Views:
    49,874
  5. DiscoStu
    Replies:
    0
    Views:
    506
    DiscoStu
    Jul 8, 2004
Loading...

Share This Page