You are viewing a plain text version of this content. The canonical link for it is here.
Posted to apache-bugdb@apache.org by Terence Lobo <lo...@snowshore.com> on 2002/01/29 01:44:45 UTC

general/9631: PrintWriter print method seems to return extra characters at the end.

>Number:         9631
>Category:       general
>Synopsis:       PrintWriter print method seems to return extra characters at the end.
>Confidential:   no
>Severity:       non-critical
>Priority:       medium
>Responsible:    apache
>State:          open
>Quarter:        
>Keywords:       
>Date-Required:
>Class:          sw-bug
>Submitter-Id:   apache
>Arrival-Date:   Mon Jan 28 16:50:00 PST 2002
>Closed-Date:
>Last-Modified:
>Originator:     lobo@snowshore.com
>Release:        Apache 1.3 + Jserv 1.2
>Organization:
apache
>Environment:
Sun Solaris 8
SunOS prompt1 5.8 Generic_108528-09 sun4u sparc SUNW,UltraAX-i2
>Description:
I have a servlet that returns some text. The servlet works fine
each time Apache is restarted but after the first time, I find a NULL
character at the end of the text. I have appended some test code below
and shows the results after invoking it:

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

public class test extends HttpServlet
{
    public void doGet (HttpServletRequest request, HttpServletResponse response)
    throws ServletException, IOException    {
       PrintWriter out = response.getWriter() ;
       response.setContentType("text/html");

       out.write("<html><head>Test</head><body>Body here</body></html>");
       out.close();
   }

    public void doPost(HttpServletRequest request, HttpServletResponse response)
    throws ServletException, IOException {
        doGet(request, response) ;
    }

    public String getServletInfo() {
       return "Just a test" ;
    }
}

The first time I invoke it I correctly get (exclude the double-quotes)
"<html><head>Test</head><body>Body here</body></html>\r\n"

But subsequently I get:
"<html><head>Test</head><body>Body here</body></html>\r\n0\r\n"

There is an extra NULL character (0) and a CR LF at the end. This
problem does not happen when the same servlet is run on TomCat and
I get the extra characters when I run any servlets (like IsITWorking
for instance). Once I restart Apache it works fine the first time and 
after that I get the extra characters all over again.

>How-To-Repeat:
The Apache/JServ install came out of the box from Sun. Guess
compiling and running on a Sun Solaris 8 machine will show the
problem.
>Fix:
Get rid of the extra characters.
>Release-Note:
>Audit-Trail:
>Unformatted:
 [In order for any reply to be added to the PR database, you need]
 [to include <ap...@Apache.Org> in the Cc line and make sure the]
 [subject line starts with the report component and number, with ]
 [or without any 'Re:' prefixes (such as "general/1098:" or      ]
 ["Re: general/1098:").  If the subject doesn't match this       ]
 [pattern, your message will be misfiled and ignored.  The       ]
 ["apbugs" address is not added to the Cc line of messages from  ]
 [the database automatically because of the potential for mail   ]
 [loops.  If you do not include this Cc, your reply may be ig-   ]
 [nored unless you are responding to an explicit request from a  ]
 [developer.  Reply only with text; DO NOT SEND ATTACHMENTS!     ]