1 16 17 package org.apache.tester; 18 19 20 import java.io.*; 21 import java.net.MalformedURLException ; 22 import java.net.URL ; 23 import javax.servlet.*; 24 import javax.servlet.http.*; 25 26 27 41 42 public class Resources02 extends HttpServlet { 43 44 public void doGet(HttpServletRequest request, HttpServletResponse response) 45 throws IOException, ServletException { 46 47 String mode = request.getParameter("mode"); 49 if (mode == null) 50 mode = "context"; 51 String path = request.getParameter("path"); 52 if (path == null) 53 path = "/WEB-INF/web.xml"; 54 55 response.setContentType("text/plain"); 57 PrintWriter writer = response.getWriter(); 58 URL url = null; 59 try { 60 if ("context".equals(mode)) 61 url = getServletContext().getResource(path); 62 else 63 url = this.getClass().getResource(path); 64 if (url == null) 65 writer.println("Resources02 PASSED"); 66 else 67 writer.println("Resources02 FAILED - Returned URL " + 68 url.toString()); 69 } catch (MalformedURLException e) { 70 writer.println("Resources02 FAILED - MalformedURLException: " 71 + e); 72 } 73 74 while (true) { 76 String message = StaticLogger.read(); 77 if (message == null) 78 break; 79 writer.println(message); 80 } 81 StaticLogger.reset(); 82 83 } 84 85 } 86 | Popular Tags |