⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 defaultcmsetter.java

📁 低版本的tomcat 对于有些老版本的应用还真的需要老版的中间件
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
	// More info - where it happended"
	buf.append("<h2>")
	    .append(sm.getString("defaulterrorpage.location"))
	    .append(" ")
	    .append(RequestUtil.filter(req.getRequestURI()))
	    .append("</h2>");

	if ( errorURI != null && contextM.getShowDebugInfo()) {
	    buf.append("\r\n<h2>")
		.append(sm.getString("defaulterrorpage.errorlocation"))
		.append(" ")
		.append(RequestUtil.filter(errorURI))
		.append("</h2>");
	}

	buf.append("<b>")
	    .append(sm.getString("defaulterrorpage.internalservleterror"));

	if (contextM.getShowDebugInfo()) {
	    buf.append("</b><br>");

	    buf.append("<pre>");

	    StringWriter sw = new StringWriter();
	    PrintWriter pw = new PrintWriter(sw);
	    e.printStackTrace(pw);

	    buf.append(sw.toString());

	    buf.append("</pre>\r\n");
	} else {
	    buf.append("</b> ")
    	        .append(e.getMessage())
		.append("<br><br>\r\n");
	}

        if (e instanceof ServletException) {
	    Throwable cause = ((ServletException)e).getRootCause();
	    if (cause != null) {
		buf.append("<b>")
		    .append(sm.getString("defaulterrorpage.rootcause"));

		if (contextM.getShowDebugInfo()) {
		    buf.append("</b>\r\n");

		    buf.append("<pre>");

		    StringWriter sw = new StringWriter();
		    PrintWriter pw = new PrintWriter(sw);
		    cause.printStackTrace( pw );
		    buf.append( sw.toString());

		    buf.append("</pre>\r\n");
		} else {
		    buf.append("</b> ")
			.append(cause.getMessage());
		}
	    }
	}
	
	buf.append("\r\n");
	
	if( res.isUsingStream() ) {
	    ServletOutputStream out = res.getOutputStream();
	    out.print(buf.toString());
	} else {
	    PrintWriter out = res.getWriter();
	    out.print(buf.toString());
	}
    }
}

class StatusHandler extends ServletWrapper {
    static StringManager sm=StringManager.
	getManager("org.apache.tomcat.resources");

    StatusHandler() {
	initialized=true;
	internal=true;
	name="tomcat.statusHandler";
    }
    
    // We don't want interceptors called for redirect
    // handler
    public void doService(Request req, Response res)
	throws Exception
    {
	String msg=(String)req.getAttribute("javax.servlet.error.message");
	String errorURI = res.getErrorURI();
	
	String charset = LocaleToCharsetMap.getCharset(Locale.getDefault());
	if (charset == null || charset.equalsIgnoreCase("ISO-8859-1"))
	    res.setContentType("text/html");
	else
	    res.setContentType("text/html; charset=" + charset);
	// res is reset !!!
	// status is already set
	int sc=res.getStatus();
	
	StringBuffer buf = new StringBuffer();
	buf.append("<head><title>");
	// if an included request originated
	if( errorURI != null ) {
	    // use error code from include
	    sc = ((Integer)req.getAttribute("javax.servlet.error.status_code")).intValue();
	    buf.append(sm.getString("defaulterrorpage.includedservlet") );
	}  else {
	    buf.append("Error: ");
	}

	buf.append( sc );
	buf.append("</title></head>\r\n");

	buf.append("<h1>");
	if( errorURI != null ) {
	    buf.append(sm.getString("defaulterrorpage.includedservlet") )
		.append(" ");
	}  else {
	    buf.append("Error: ");
	}
	
	buf.append( sc );
	buf.append("</h1>\r\n");

	// More info - where it happended"
	buf.append("<h2>")
	    .append(sm.getString("defaulterrorpage.location"))
	    .append(" ")
	    .append(RequestUtil.filter(req.getRequestURI()))
	    .append("</h2>");

	if ( sc >= 400 && errorURI != null && contextM.getShowDebugInfo()) {
	    buf.append("\r\n<h2>")
		.append(sm.getString("defaulterrorpage.errorlocation"))
		.append(" ")
		.append(RequestUtil.filter(errorURI))
		.append("</h2>");
	}

	buf.append("<b>")
	    .append(RequestUtil.filter(msg))
	    .append("</b><br>");

	// add unavailable time if present
	if ( sc == 503) {
            Integer ut = (Integer)req.getAttribute("tomcat.servlet.error.unavailableTime");
            if ( ut != null) {
                // if permanent
                if (ut.intValue() < 0) {
		    buf.append("<br>")
                	.append(sm.getString("defaulterrorpage.service.permanently.unavailable"))
			.append("<br>");
                } else {
		    buf.append("<br>")
                	.append(sm.getString("defaulterrorpage.service.unavailable",ut))
			.append("<br>");
                }
	    }
	}

	buf.append("</body>\r\n");

	if( res.isUsingStream() ) {
	    ServletOutputStream out = res.getOutputStream();
	    out.print(buf.toString());
	} else {
	    PrintWriter out = res.getWriter();
	    out.print(buf.toString());
	}
    }

}
	
class RedirectHandler extends ServletWrapper {
    static StringManager sm=StringManager.
	getManager("org.apache.tomcat.resources");

    RedirectHandler() {
	initialized=true;
	internal=true;
	name="tomcat.redirectHandler";
    }

    // We don't want interceptors called for redirect
    // handler
    public void doService(Request req, Response res)
	throws Exception
    {
	String location	= (String)
	    req.getAttribute("javax.servlet.error.message");
	Context ctx=req.getContext();
	
	location = makeAbsolute(req, location);

	if( debug>0) ctx.log("Redirect " + location + " " + req );

	String charset = LocaleToCharsetMap.getCharset(Locale.getDefault());
	if (charset == null || charset.equalsIgnoreCase("ISO-8859-1"))
	    res.setContentType("text/html");
	else
	    res.setContentType("text/html; charset=" + charset);
	res.setHeader("Location", location);

	StringBuffer buf = new StringBuffer();
	buf.append("<head><title>").
	    append(sm.getString("defaulterrorpage.documentmoved")).
	    append("</title></head>\r\n<body><h1>").
	    append(sm.getString("defaulterrorpage.documentmoved")).
	    append("</h1>\r\n").
	    append(sm.getString("defaulterrorpage.thisdocumenthasmoved")).
	    append(" <a href=\"").
	    append(RequestUtil.filter(location)).
	    append("\">here</a>.<p>\r\n</body>\r\n");

	String body = buf.toString();

	res.setContentLength(body.length());

	if( res.isUsingStream() ) {
	    ServletOutputStream out = res.getOutputStream();
	    out.print(body);
	    out.flush();
	} else {
	    PrintWriter out = res.getWriter();
	    out.print(body);
	    out.flush();
	}
    }

    // XXX Move it to URLUtil !!!
    private String makeAbsolute(Request req, String location) {
        URL url = null;
        try {
	    // Try making a URL out of the location
	    // Throws an exception if the location is relative
            url = new URL(location);
	} catch (MalformedURLException e) {
	    String requrl = HttpUtils.getRequestURL(req.getFacade()).
		toString();
	    try {
	        url = new URL(new URL(requrl), location);
	    }
	    catch (MalformedURLException ignored) {
	        // Give up
	        return location;
	    }
	}
        return url.toString();
    }
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -