alvinalexander.com | career | drupal | java | mac | mysql | perl | scala | uml | unix  

What this is

This file is included in the DevDaily.com "Java Source Code Warehouse" project. The intent of this project is to help you "Learn Java by Example" TM.

Other links

The source code

/*
 *  Copyright 1999-2004 The Apache Software Foundation
 *
 *  Licensed under the Apache License, Version 2.0 (the "License");
 *  you may not use this file except in compliance with the License.
 *  You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 *  Unless required by applicable law or agreed to in writing, software
 *  distributed under the License is distributed on an "AS IS" BASIS,
 *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *  See the License for the specific language governing permissions and
 *  limitations under the License.
 */

import java.io.IOException;
import java.io.PrintWriter;
import java.util.Enumeration;
import javax.servlet.*;
import javax.servlet.http.*;

/**
 *
 *
 * @author James Duncan Davidson 
 * @author Jason Hunter 
 */
public class RequestDump extends HttpServlet {

    public void doPost(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException
    {
	doGet( request, response );
    }
    
    public void doGet(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException
    {
	dumpRequest(this, request, response );
    }
    
    public static void dumpRequest(HttpServlet servlet, HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException
    {
        PrintWriter out = response.getWriter();
        response.setContentType("text/html");
	Enumeration enum, names, e;

	ServletContext context=servlet.getServletContext();
        out.println();
        out.println("

Request info

"); out.println(""); out.println(""); out.println(""); out.println(""); out.println(""); out.println(""); out.println(""); out.println(""); out.println(""); out.println(""); out.println(""); out.println(""); out.println(""); out.println(""); out.println(""); out.println(""); out.println(""); out.println(""); out.println(""); out.println(""); out.println(""); out.println(""); out.println(""); out.println(""); HttpSession session = request.getSession(false); if( session!=null ) { out.println(""); out.println(""); out.println(""); out.println(""); out.println(""); } out.println("
Servlet Name" + servlet.getServletName() + "
Protocol" + request.getProtocol() + "
Scheme" + request.getScheme() + "
Server Name" + request.getServerName() + "
Server Port" + request.getServerPort() + "
Server Info" + context.getServerInfo() + "
Remote Addr" + request.getRemoteAddr() + "
Remote Host" + request.getRemoteHost() + "
Character Encoding" + request.getCharacterEncoding() + "
Content Length" + request.getContentLength() + "
Content Type"+ request.getContentType() + "
Locale"+ request.getLocale() + "
Default Response Buffer"+ response.getBufferSize() + "
Request Is Secure" + request.isSecure() + "
Auth Type" + request.getAuthType() + "
HTTP Method" + request.getMethod() + "
Remote User" + request.getRemoteUser() + "
Request URI" + request.getRequestURI() + "
Context Path" + request.getContextPath() + "
Servlet Path" + request.getServletPath() + "
Path Info" + request.getPathInfo() + "
Path Trans" + request.getPathTranslated() + "
Query String" + request.getQueryString() + "
Requested Session Id" + request.getRequestedSessionId() + "
Current Session Id" + session.getId() + "
Session Created Time" + session.getCreationTime() + "
Session Last Accessed Time" + session.getLastAccessedTime() + "
Session Max Inactive Interval Seconds" + session.getMaxInactiveInterval() + "
"); out.println("

Parameters

"); out.println(""); e = request.getParameterNames(); while (e.hasMoreElements()) { String key = (String)e.nextElement(); String[] values = request.getParameterValues(key); out.print(""); } out.println("
" + key + ""); for(int i = 0; i < values.length; i++) { out.print("" + values[i] + " "); } out.println("
"); out.println("

Headers

"); out.println(""); e = request.getHeaderNames(); while (e.hasMoreElements()) { String key = (String)e.nextElement(); String value = request.getHeader(key); out.println("" ); } out.println("
" + key + "" + value + "
"); out.println("

Cookies

"); out.println(""); Cookie[] cookies = request.getCookies(); for (int i = 0; i < cookies.length; i++) { Cookie cookie = cookies[i]; out.println("" ); } out.println("
" + cookie.getName() + "" + cookie.getValue() + "
"); if( session != null ) { out.println("

Session

"); out.println(""); names = session.getAttributeNames(); while (names.hasMoreElements()) { String name = (String) names.nextElement(); out.println("" ); } out.println("
" + name + "" + session.getAttribute(name) + "
"); } out.println("

Request attributes

"); out.println(""); e = request.getAttributeNames(); while (e.hasMoreElements()) { String key = (String)e.nextElement(); Object value = request.getAttribute(key); out.println("" ); } out.println("
" + key + "" + value + "
"); out.println("

Context attributes:

"); out.println(""); enum = context.getAttributeNames(); while (enum.hasMoreElements()) { String key = (String)enum.nextElement(); Object value = context.getAttribute(key); out.println("" ); } out.println("
" + key + "" + value + "
"); out.println("

Servlet init parameters

"); out.println(""); e = servlet.getInitParameterNames(); while (e.hasMoreElements()) { String key = (String)e.nextElement(); String value = servlet.getInitParameter(key); out.println("" ); } out.println("
" + key + "" + value + "
"); out.println("

Context init parameters

"); out.println(""); enum = context.getInitParameterNames(); while (enum.hasMoreElements()) { String key = (String)enum.nextElement(); Object value = context.getInitParameter(key); out.println("" ); } out.println("
" + key + "" + value + "
"); } }
... this post is sponsored by my books ...

#1 New Release!

FP Best Seller

 

new blog posts

 

Copyright 1998-2024 Alvin Alexander, alvinalexander.com
All Rights Reserved.

A percentage of advertising revenue from
pages under the /java/jwarehouse URI on this website is
paid back to open source projects.