tomcat-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Tim Funk <funk...@joedog.org>
Subject Re: Example error pages?
Date Fri, 30 May 2003 01:35:44 GMT
D'oh. Didn't make it. Here it is inline ... This is also a classic example of 
everything ugly jsp ;) (But it works real nice for me) ...

-Tim

--start of page--
<%@ page import="java.net.InetAddress"
          import="java.util.Enumeration" %>

<%
   Cookie[] cookies = request.getCookies();
   String reqSessionId = request.getRequestedSessionId();
%>
<STYLE>
<!--
TABLE{
     text-align : left;
     vertical-align: top;
}
TH,TD,P, PRE {
     font-size : 11px
}
-->
</STYLE>

<font face="Helvetica">

<h1>
<font color=#DB1260>
Environment Information
</font>
</h1>
<PRE>
javax.servlet.include.request_uri: 
<%=request.getAttribute("javax.servlet.include.request_uri")%>
</PRE>
<p>
<%
   out.println( "<TABLE BORDER=0>\n" );
   out.println( 
"<TR><TH>Server:</TD><TD>"+request.getServerName()+"</TD></TR>\n");
   try {
       out.println( 
"<TR><TH>SERVER::getHostName():</TD><TD>"+InetAddress.getLocalHost().getHostName()+"</TD></TR>\n");
   } catch(Throwable e){
       out.println( "<TR><TH>SERVER::getHostName():</TD><TD>"+e+"</TD></TR>\n");
   }
   try {
       out.println( 
"<TR><TH>SERVER::getHostAddress():</TD><TD>"+InetAddress.getLocalHost().getHostAddress()+"</TD></TR>\n");
   } catch(Throwable e){
       out.println( 
"<TR><TH>SERVER::getHostAddress():</TD><TD>"+e+"</TD></TR>\n");
   }
   out.println( "<TR><TH>Client Remote 
Addr:</TD><TD>"+request.getRemoteHost()+"</TD></TR>\n");
   out.println( "<TR><TH>Client Remote 
Host:</TD><TD>"+request.getRemoteAddr()+"</TD></TR>\n");
   out.println( 
"<TR><TH>Protocol</TD><TD>"+request.getProtocol()+"</TD></TR>\n");
   out.println( "<TR><TH>SessionID:</TD><TD>"+reqSessionId+"</TD></TR>\n");
   out.println( 
"<TR><TH>request.getRequestURI():</TD><TD>"+request.getRequestURI()+"</TD></TR>\n");


   out.println( 
"<TR><TH>getQueryString:</TD><TD>"+request.getQueryString()+"</TD></TR>");
   out.println( 
"<TR><TH>getAttributeNames:</TD><TD>"+request.getAttributeNames()+"</TD></TR>");
   out.println( 
"<TR><TH>getParameterNames:</TD><TD>"+request.getParameterNames()+"</TD></TR>");
   out.println( 
"<TR><TH>getContextPath:</TD><TD>"+request.getContextPath()+"</TD></TR>");
   out.println( 
"<TR><TH>getPathInfo:</TD><TD>"+request.getPathInfo()+"</TD></TR>");
   out.println( 
"<TR><TH>getRequestURI:</TD><TD>"+request.getRequestURI()+"</TD></TR>");
   out.println( 
"<TR><TH>getServletPath:</TD><TD>"+request.getServletPath()+"</TD></TR>");
   out.println( 
"<TR><TH>servletConfig.getServletName:</TD><TD>"+getServletConfig().getServletName()+"</TD></TR>");



   for( int x = 0; cookies!=null && x < cookies.length; x++ ){
     Cookie cookie = cookies[x];
     out.println( "<TR><TH>Cookie:</TD><TD>" +cookie.getValue()+"</TD></TR>\n");
   }
   out.println( "</TABLE>\n" );

   out.println( "<H2>Headers</H2>" );
   out.println( "<TABLE BORDER=0>\n" );

   for (Enumeration e = request.getHeaderNames(); e!=null && 
e.hasMoreElements(); ) {
     String key = (String)e.nextElement();
     for (Enumeration ei = request.getHeaders(key); ei!=null && 
ei.hasMoreElements(); ) {
       out.println( "<TR><TH>" + key + "</TD><TD>" + ei.nextElement()
+ 
"</TD></TR>\n");
     }
   }
   out.println( "</TABLE>\n" );

%>

<HR>
<H2>Servlet Context</H2>
<%
     ServletContext sc = this.getServletConfig().getServletContext();
     for (Enumeration e = sc.getAttributeNames(); e!=null && 
e.hasMoreElements(); ) {
         String key = (String)e.nextElement(); %>
<%=key%>: <%=sc.getAttribute(key)%><%
     }
%>

<HR>
<H2>Session Object</H2>
<%
     for (Enumeration e = session.getAttributeNames(); e!=null && 
e.hasMoreElements(); ) {
         String key = (String)e.nextElement(); %>
<%=key%>: <%=session.getAttribute(key)%><%
     }
%>

<HR>
<H2>Requests Object</H2>
<PRE><%
     for (Enumeration e = request.getAttributeNames(); e!=null && 
e.hasMoreElements(); ) {
         String key = (String)e.nextElement(); %>
<%=key%>: <%=request.getAttribute(key)%><%
     }
%>

<%
     if (request.getAttribute("thrown")!=null) {
         Throwable e = (Throwable)request.getAttribute("thrown");
         while (e!=null) {
             if (e instanceof javax.servlet.ServletException ){
                 out.println("ROOT CAUSE:\n" + 
getStackTrace(((javax.servlet.ServletException)e).getRootCause()));
                 e = (((javax.servlet.ServletException)e).getRootCause());
             } else if (e instanceof javax.servlet.jsp.JspException ){
                 out.println("ROOT CAUSE:\n" + 
getStackTrace(((javax.servlet.jsp.JspException)e).getRootCause()));
                 e = (((javax.servlet.jsp.JspException)e).getRootCause());
             } else {
                 out.println("ROOT CAUSE:\n" + getStackTrace(e));
                 e=null;
             }
         }
     }
%>

<%

         StringBuffer s = new StringBuffer();

         java.lang.reflect.Field[] f = request.getClass().getDeclaredFields();
         java.lang.reflect.Method[] m = request.getClass().getMethods();

         s.append("FIELDS:\n");
         for( int i=0; i< f.length; i++ ) {
             try {
                 s.append(f[i].getName() + "=" + f[i].get(request) + "\n");
             } catch (IllegalAccessException mf) {
//                s.append("... Exception ..." );
             } catch (Throwable mf) {
                 s.append("... " + mf.toString() + " ...\n" );
             }
         }

         for( int i=0; i<m.length; i++ ) {
             try {
                 //only get "get" or "is" methods ...
                 if ( m[i].getParameterTypes().length==0 &&
                      (  m[i].getName().startsWith("is") ||
                         m[i].getName().startsWith("get") ||
                         m[i].getName().startsWith("siz"))
                    )
                     s.append(m[i].getName() + "=" + m[i].invoke(request, new 
Object[0]) + "\n");
             } catch (IllegalAccessException mf) {
                 //s.append("... IllegalAccessException ..." );
//                s.append(m[i].getName()  + ":!! " + mf.toString() + " ...\n" );
             } catch (Throwable mf) {
                 s.append(m[i].getName()  + ":!! " + mf.toString() + " ...\n" );
             }
         }

         out.println(s.toString());

%>
</PRE>

<PRE>
Classloader hiererarchy ...
<%
     String indent = "";
     ClassLoader cl = this.getClass().getClassLoader();
     ClassLoader lcl = null;
     while (cl != null && lcl != cl) {
         lcl = cl;
         out.println(indent + cl.getClass().getName() + "[" + cl + "]");
         indent += "  ";
         cl = cl.getParent();
     }
%>
</PRE>

</p>
</font>
<%!
     String getStackTrace(Throwable e) {
         try {
             java.io.StringWriter s = new java.io.StringWriter();
             java.io.PrintWriter  p = new java.io.PrintWriter(s);
             e.printStackTrace( p );
             p.close();
             s.close();
             return s.toString();
         } catch(Throwable q) {
             return "no stacktrace";
         }
     }

%>

--End of page--



---------------------------------------------------------------------
To unsubscribe, e-mail: tomcat-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tomcat-user-help@jakarta.apache.org


Mime
View raw message