1 package org.mortbay.http.handler; 16 import java.io.IOException ; 17 import java.io.Writer ; 18 import java.net.URLDecoder ; 19 20 import org.mortbay.http.HttpException; 21 import org.mortbay.http.HttpFields; 22 import org.mortbay.http.HttpRequest; 23 import org.mortbay.http.HttpResponse; 24 import org.mortbay.util.ByteArrayISO8859Writer; 25 import org.mortbay.util.StringUtil; 26 27 35 public class ErrorPageHandler extends AbstractHttpHandler 36 { 37 38 public void handle( 39 String pathInContext, 40 String pathParams, 41 HttpRequest request, 42 HttpResponse response) 43 throws HttpException, IOException 44 { 45 response.setContentType(HttpFields.__TextHtml); 46 ByteArrayISO8859Writer writer= new ByteArrayISO8859Writer(2048); 47 writeErrorPage(request, writer, response.getStatus(), response.getReason()); 48 writer.flush(); 49 response.setContentLength(writer.size()); 50 writer.writeTo(response.getOutputStream()); 51 writer.destroy(); 52 } 53 54 55 protected void writeErrorPage(HttpRequest request, Writer writer, int code, String message) 56 throws IOException 57 { 58 if (message != null) 59 { 60 message=URLDecoder.decode(message,"UTF-8"); 61 message= StringUtil.replace(message, "<", "<"); 62 message= StringUtil.replace(message, ">", ">"); 63 } 64 String uri= request.getPath(); 65 uri= StringUtil.replace(uri, "<", "<"); 66 uri= StringUtil.replace(uri, ">", ">"); 67 writer.write("<html>\n<head>\n<title>Error "); 68 writer.write(Integer.toString(code)); 69 writer.write(' '); 70 writer.write(message); 71 writer.write("</title>\n</head>\n<body>\n<h2>HTTP ERROR: "); 72 writer.write(Integer.toString(code)); 73 writer.write("</h2><pre>"); 74 writer.write(message); 75 writer.write("</pre>\n"); 76 writer.write("<p>RequestURI="); 77 writer.write(uri); 78 writer.write( 79 "</p>\n<p><i><small><a HREF=\"http://jetty.mortbay.org\">Powered by Jetty://</a></small></i></p>"); 80 for (int i= 0; i < 20; i++) 81 writer.write("\n "); 82 writer.write("\n</body>\n</html>\n"); 83 } 84 } 85 | Popular Tags |