1 16 17 package org.apache.tester; 18 19 20 import java.io.*; 21 import javax.servlet.*; 22 import javax.servlet.http.*; 23 24 37 38 public class Include03 extends HttpServlet { 39 40 private static final String specials[] = 41 { "javax.servlet.include.request_uri", 42 "javax.servlet.include.context_path", 43 "javax.servlet.include.servlet_path", 44 "javax.servlet.include.path_info", 45 "javax.servlet.include.query_string" }; 46 47 48 public void doGet(HttpServletRequest request, HttpServletResponse response) 49 throws IOException, ServletException { 50 51 StringBuffer sb = new StringBuffer (); 53 response.setContentType("text/plain"); 54 PrintWriter writer = response.getWriter(); 55 56 String path = request.getParameter("path"); 58 if (path == null) 59 path = "/Include03a"; 60 61 RequestDispatcher rd = 63 getServletContext().getRequestDispatcher(path); 64 if (rd == null) { 65 sb.append(" No RequestDispatcher returned/"); 66 } else { 67 rd.include(request, response); 68 } 69 response.resetBuffer(); 70 71 String value = null; 73 try { 74 value = (String ) 75 request.getAttribute(path.substring(1)); 76 } catch (ClassCastException e) { 77 sb.append(" Returned attribute not of type String/"); 78 } 79 if ((sb.length() < 1) && (value == null)) { 80 sb.append(" No includee-created attribute was returned/"); 81 } 82 83 for (int i = 0; i < specials.length; i++) { 85 if (request.getAttribute(specials[i]) != null) { 86 sb.append(" Returned attribute "); 87 sb.append(specials[i]); 88 sb.append("/"); 89 } 90 } 91 92 if (sb.length() < 1) 94 writer.println("Include03 PASSED"); 95 else { 96 writer.print("Include03 FAILED -"); 97 writer.println(sb.toString()); 98 } 99 100 while (true) { 101 String message = StaticLogger.read(); 102 if (message == null) 103 break; 104 writer.println(message); 105 } 106 StaticLogger.reset(); 107 108 } 109 110 } 111 | Popular Tags |