1 16 17 package org.apache.tester; 18 19 20 import java.io.*; 21 import java.lang.reflect.*; 22 import java.util.*; 23 import javax.servlet.*; 24 import javax.servlet.http.*; 25 26 27 36 37 public class FilterRequest01 extends HttpServlet { 38 39 public void service(HttpServletRequest request, 40 HttpServletResponse response) 41 throws IOException, ServletException { 42 43 response.setContentType("text/plain"); 44 PrintWriter writer = response.getWriter(); 45 StringBuffer sb = new StringBuffer (); 46 47 String type = request.getParameter("type"); 48 if (type == null) 49 type = "reader"; 50 if (type.equalsIgnoreCase("reader")) { 51 BufferedReader br = request.getReader(); 52 while (true) { 53 int c = br.read(); 54 if (c < 0) 55 break; 56 sb.append((char) c); 57 } 58 br.close(); 59 } else { 60 ServletInputStream sis = request.getInputStream(); 61 while (true) { 62 int c = sis.read(); 63 if (c < 0) 64 break; 65 sb.append((char) c); 66 } 67 sis.close(); 68 } 69 70 writer.println(sb.toString()); 71 while (true) { 72 String message = StaticLogger.read(); 73 if (message == null) 74 break; 75 writer.println(message); 76 } 77 StaticLogger.reset(); 78 79 } 80 81 } 82 | Popular Tags |