You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Andy Engle <st...@andyengle.com> on 2004/04/07 18:03:08 UTC

Easily printing out session values

Hi all,

Is there a way to simply print out session values, such as through the
bean:write tag or something like that?  If there is, could you please
share?  It seems like it should be easily done, but I can't find
anything that describes how to.

Thanks!


Andy


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


Re: Easily printing out session values

Posted by James Mitchell <jm...@apache.org>.
Seems the attachment was stripped.......

Here it is:


<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib uri="/WEB-INF/struts-html.tld"    prefix="html" %>
<%@ taglib uri="/WEB-INF/struts-tiles.tld"   prefix="tiles" %>
<%@ taglib uri="/WEB-INF/struts-bean.tld"    prefix="bean" %>
<%@ taglib uri="http://java.sun.com/jstl/core" prefix="c"%>

<hr width="3px">
Debug Information:<br>
<table border="1" width="50%" class="debug">
 <tr>
  <th colspan="2" style="background:aqua"><b>Request Parameters</b></th>
 </tr>
 <c:forEach items="${paramValues}" var="parameter">
   <tr>
  <td><c:out value="${parameter.key}"/></td>
  <td>
  <c:forEach var="value" items="${parameter.value}">
   <c:out value="${value}"/>
  </c:forEach>
  </td>
   </tr>
 </c:forEach>

 <tr>
  <th colspan="2" style="background:aqua"><b>Header Values</b></th>
 </tr>
 <c:forEach items="${header}" var="h">
   <tr>
  <td><c:out value="${h.key}"/></td>
  <td>
  <c:out value="${h.value}"/>
  </td>
   </tr>
 </c:forEach>

 <tr>
  <th colspan="2" style="background:aqua"><b>Initialization
Parameters</b></th>
 </tr>
 <c:forEach items="${initParam}" var="parameter">
   <tr>
  <td><c:out value="${parameter.key}"/></td>
  <td><c:out value="${parameter.value}"/></td>
   </tr>
 </c:forEach>

 <tr>
  <th colspan="2" style="background:aqua"><b>Cookies</b></th>
 </tr>
 <c:forEach items="${cookie}" var="mapEntry">
   <tr>
  <td><c:out value="${mapEntry.key}"/></td>
  <td><c:out value="${mapEntry.value}"/></td>
   </tr>
 </c:forEach>


 <tr>
  <th colspan="2" style="background:aqua"><b>page</b></th>
 </tr>
 <c:forEach items="${pageScope}" var="itm">
   <tr>
  <td><c:out value="${itm.key}"/></td>
  <td><c:out value="${itm.value}"/></td>
   </tr>
 </c:forEach>


 <tr>
  <th colspan="2" style="background:aqua"><b>request</b></th>
 </tr>
 <c:forEach items="${requestScope}" var="itm">
   <tr>
  <td><c:out value="${itm.key}"/></td>
  <td><c:out value="${itm.value}"/></td>
   </tr>
 </c:forEach>


 <tr>
  <th colspan="2" style="background:aqua"><b>session</b></th>
 </tr>
 <c:forEach items="${sessionScope}" var="itm">
   <tr>
  <td><c:out value="${itm.key}"/></td>
  <td><c:out value="${itm.value}"/></td>
   </tr>
 </c:forEach>


 <tr>
  <th colspan="2" style="background:aqua"><b>application</b></th>
 </tr>
 <c:forEach items="${applicationScope}" var="itm">
   <tr>
  <td><c:out value="${itm.key}"/></td>
  <td><c:out value="${itm.value}"/></td>
   </tr>
 </c:forEach>
</table>




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


Re: Easily printing out session values

Posted by James Mitchell <jm...@apache.org>.
Here's a nice little debug.jsp that I use in my footer...


--
James Mitchell
Software Engineer / Open Source Evangelist
EdgeTech, Inc.
678.910.8017
AIM: jmitchtx
MSN: jmitchell@apache.org
Yahoo IM:jmitchtx@yahoo.com



----- Original Message ----- 
From: "Andy Engle" <st...@andyengle.com>
To: <us...@struts.apache.org>
Sent: Wednesday, April 07, 2004 12:03 PM
Subject: Easily printing out session values


> Hi all,
> 
> Is there a way to simply print out session values, such as through the
> bean:write tag or something like that?  If there is, could you please
> share?  It seems like it should be easily done, but I can't find
> anything that describes how to.
> 
> Thanks!
> 
> 
> Andy
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org
> 


Re: Easily printing out session values

Posted by Niall Pemberton <ni...@blueyonder.co.uk>.
You could use the page tag to expose the session as a variable:

   <bean:page id="sessionVar" property="session"/>

The you could use <bean:write> for example

   <bean:write name="sessionVar" property="creationTime"/>


Niall

----- Original Message ----- 
From: "Andy Engle" <st...@andyengle.com>
To: <us...@struts.apache.org>
Sent: Wednesday, April 07, 2004 5:03 PM
Subject: Easily printing out session values


> Hi all,
> 
> Is there a way to simply print out session values, such as through the
> bean:write tag or something like that?  If there is, could you please
> share?  It seems like it should be easily done, but I can't find
> anything that describes how to.
> 
> Thanks!
> 
> 
> Andy
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org
> 
> 
> 


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


Re: Easily printing out session values

Posted by Richard Yee <ry...@yahoo.com>.
Andy,
Put this in your jsp page. If you create a JSP
template file that includes this code and then use it
as a basis for developing new JSP pages, you will be
able to see what is in your request, session and
ActionMessages. I found it in this article on
javaboutique by Keld H. Hanson:
http://javaboutique.internet.com/tutorials/excep_struts/

Regards,

Richard


<%@ page import="java.util.*" %>
<%@ page import="org.apache.struts.*" %>
<%@ page import="org.apache.struts.util.*" %>
<%@ page import="org.apache.struts.action.*" %>

<%
  // Print all attributes in the request object
  out.println("<p><b>All Attributes in request
scope:</b>");
  Enumeration paramNames =
request.getAttributeNames();
  while (paramNames.hasMoreElements()) {
    String name = (String) paramNames.nextElement();
    Object values = request.getAttribute(name);
    out.println("<br> " + name + ":" + values);
  }
  
  // Print all attributes in the session object
  out.println("<p><b>All Attributes in session
scope:</b>");
  paramNames = session.getAttributeNames();
  while (paramNames.hasMoreElements()) {
    String name = (String) paramNames.nextElement();
    Object values = session.getAttribute(name);
    out.println("<br> " + name + ":" + values);
  }

  out.println("<p><b>Data in ActionMessages:</b>");

  // Get the ActionMessages 
  Object o =
request.getAttribute(Globals.MESSAGE_KEY);
  if (o != null) {
    ActionMessages ae = (ActionMessages)o;

    // Get the locale and message resources bundle
    Locale locale = 
     
(Locale)session.getAttribute(Globals.LOCALE_KEY);
    MessageResources messages = 
      (MessageResources)request.getAttribute
      (Globals.MESSAGES_KEY);

    // Loop thru all the labels in the ActionMessage's
 
    for (Iterator i = ae.properties(); i.hasNext();) {
      String property = (String)i.next();
      out.println("<br>property " + property + ": ");

      // Get all messages for this label
      for (Iterator it = ae.get(property);
it.hasNext();) {
        ActionMessage a = (ActionMessage)it.next();
        String key = a.getKey();
        Object[] values = a.getValues();
        out.println(" [key=" + key + 
          ", message=" + 
          messages.getMessage(locale,key,values) + 
          "]");
      }
    }
  }
%>

--- Andy Engle <st...@andyengle.com> wrote:
> Hi all,
> 
> Is there a way to simply print out session values,
> such as through the
> bean:write tag or something like that?  If there is,
> could you please
> share?  It seems like it should be easily done, but
> I can't find
> anything that describes how to.
> 
> Thanks!
> 
> 
> Andy
> 
> 
>
---------------------------------------------------------------------
> To unsubscribe, e-mail:
> user-unsubscribe@struts.apache.org
> For additional commands, e-mail:
> user-help@struts.apache.org
> 


__________________________________
Do you Yahoo!?
Yahoo! Small Business $15K Web Design Giveaway 
http://promotions.yahoo.com/design_giveaway/

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