Re: testing output stream of doGet failed
Kazuhito SUGURI <[email protected]>
| Newsgroups | gmane.comp.jakarta.cactus.user |
|---|---|
| Message-ID | <[email protected]> |
Hi, In article <FA6F7D6E5D6BF34695A7407F4745AF9A391F07@BLRKECMSG13.ad.infosys.com>, Thu, 19 Jan 2006 09:51:37 +0530, "214060 - Shou Jiesong" <[email protected]> wrote: 214060> public void doGet(HttpServletRequest request, [snip] 214060> response.setContentType("text/html"); 214060> 214060> PrintWriter out = response.getWriter(); 214060> 214060> out.print("<html><head><title>Testing Servlets</title>" + 214060> 214060> "</title></head><body><h1>Count is " + count + 214060> 214060> "</h1></body></html>"); 214060> 214060> out.close(); In this context, PrintWriter#close() method commits the response body, and then, subsequent output (i.e. print method calls) will be ignored. 214060> I observed that the test failed. I called doGet() twice and it was 214060> suppose to increase count to 2. it does in testDoGet() since I could see 214060> the printed result; it was 2. 214060> 214060> But in endDoGet(), the count was always 1 whatever how many times 214060> doGet() was called in testDoGet(). If you want test if the count is properlly incremented, you might set the session attribute before doGet() method get called. For example: Integer prevCount = new Integer(1); session.setAttribute("Count", prevCount); doGet(request, response); Hope this helps, ---- Kazuhito SUGURI