开发者

JSP code to view request and response and session contents

I 开发者_Python百科am trying to debug an issue where either the HTTP Session is being dropped or the cookie is not being sent back by the browser. Due to the security contstraints that we have to deal with, I am left with needing a JSP That I can drop on the server that will display the contents of the Request, the Response, and the contents of the HTTP Session.

Does anyone have any code that will do this? It should be a self-contained JSP that I can drop into an existing WAR file (so assume I only have access to the default Sun java libraries).


Put the below in a jsp file and and you will get all the info you asked for

<%

out.println("<h1>application scope</h1>");
java.util.Enumeration e=application.getAttributeNames();
out.println("<table border='3' width='1000px'>");
while(e.hasMoreElements())
    {
        String name=(String)e.nextElement();

        Object value=application.getAttribute(name);
        if(value==null)
        {
        value="NONE";
        }
        System.out.println(name+":"+value);
        if(!name.contains("ibm") && !name.contains("myfaces")       )
        {
            if(value!=null && value.getClass().toString().contains("versata"))
            {
                out.println("<tr style='font-weight:bold;color:red;'>");        
            }
            else
            {
                out.println("<tr>");    
            }
                out.println("<td>");        
                out.println("Name: "+name);
                out.println("</td>");       
                out.println("<td>");        
                out.println("Value: "+value);
                out.println("</td>");       
                if(value!=null)
                {
                out.println("<td>");        
                out.println("Class: "+value.getClass());
                out.println("</td>");       
                }
                out.println("</tr>");       
        }
    }
out.println("</table>");
out.println("<h1>session scope</h1>");

e=session.getAttributeNames();
out.println("<table border='3' width='1000px'>");
while(e.hasMoreElements())
    {
        String name=(String)e.nextElement();

        Object value=application.getAttribute(name);
        if(value==null)
        {
        value="NONE";
        }
        System.out.println(name+":"+value);
        if(!name.contains("ibm") && !name.contains("myfaces")       )
        {
            if(value!=null && value.getClass().toString().contains("versata"))
            {
                out.println("<tr style='font-weight:bold;color:red;'>");        
            }
            else
            {
                out.println("<tr>");    
            }
                out.println("<td>");        
                out.println("Name: "+name);
                out.println("</td>");       
                out.println("<td>");        
                out.println("Value: "+value);
                out.println("</td>");       
                if(value!=null)
                {
                out.println("<td>");        
                out.println("Class: "+value.getClass());
                out.println("</td>");       
                }
                out.println("</tr>");       
        }
    }
out.println("</table>");

out.println("<h1>request scope</h1>");

e=request.getAttributeNames();
out.println("<table border='3' width='1000px'>");
while(e.hasMoreElements())
    {
        String name=(String)e.nextElement();

        Object value=application.getAttribute(name);
        if(value==null)
        {
        value="NONE";
        }
        System.out.println(name+":"+value);
        if(!name.contains("ibm") && !name.contains("myfaces")       )
        {
            if(value!=null && value.getClass().toString().contains("versata"))
            {
                out.println("<tr style='font-weight:bold;color:red;'>");        
            }
            else
            {
                out.println("<tr>");    
            }
                out.println("<td>");        
                out.println("Name: "+name);
                out.println("</td>");       
                out.println("<td>");        
                out.println("Value: "+value);
                out.println("</td>");       
                if(value!=null)
                {
                out.println("<td>");        
                out.println("Class: "+value.getClass());
                out.println("</td>");       
                }
                out.println("</tr>");       
        }
    }
out.println("</table>");

%>
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜