日期:2014-05-16  浏览次数:20345 次

JSP中打印Struts2的值栈(ValueStack)和ActionContext
<%@ page import="com.opensymphony.xwork2.*"%>
   <%@ page import="com.opensymphony.xwork2.util.*"%>
   <%@ page import="java.util.*"%>
  

   <%
    ActionContext cxt = ActionContext.getContext();

    out.println("<h2>ValueStack</h2>");
    ValueStack stack = cxt.getValueStack();
    List list = (List) stack.getRoot();
    for (int i=0; i<list.size(); i++)
    {
     out.print("<FONT Color='Red'>" + list.get(i)+"</FONT>");
     out.println("<BR/>");
    }
   
    out.println("<h2>ContextMap</h2>");
    Map map = cxt.getContextMap();
    Set set = map.entrySet();
    for (Iterator it = set.iterator(); it.hasNext();)
    {
     Map.Entry es = (Map.Entry) it.next();
     // key
     out.print("<B><Font Color='Red'>"+es.getKey()+"</FONT></B>");
     // value
     out.print("=" + es.getValue());
     out.println("<br/>");
    }
   %>