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 Resources01 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("Resources01 FAILED - No URL was returned"); 66 else { 67 writer.println("Resources01 PASSED"); 68 writer.println("url = " + url.toString()); 69 } 70 } catch (MalformedURLException e) { 71 writer.println("Resources01 FAILED - MalformedURLException: " 72 + e); 73 } 74 75 while (true) { 77 String message = StaticLogger.read(); 78 if (message == null) 79 break; 80 writer.println(message); 81 } 82 StaticLogger.reset(); 83 84 } 85 86 } 87 | Popular Tags |