在Struts2在 <s:debug> 標籤是一個非常有用的調試標記輸出“值棧”的內容,並在網頁中“堆疊上下文”的詳細資訊。在本教程,在JSP頁面中顯示如何使用<s:debug>標籤。
1. 動作
一個簡單的Action類,帶有 propertyInStack 屬性,顯示疊加後的值。
DebugTagAction.java
package com.xuhuhu.common.action; import com.opensymphony.xwork2.ActionSupport; public class DebugTagAction extends ActionSupport{ public String propertyInStack; public String getPropertyInStack() { return propertyInStack; } public void setPropertyInStack(String propertyInStack) { this.propertyInStack = propertyInStack; } }
2. <s:date>標籤示例
在JSP頁面使用<s:debug>標籤輸出系統的“值棧”和“棧上下文”。
debug.jsp
<%@ taglib prefix="s" uri="/struts-tags" %> <html> <head> </head> <body> <h1>Struts2 <s:debug>標籤示例 - www.xuhuhu.com</h1> <s:debug /> </body> </html>
將生成一個名為 debug 文字鏈接,點擊文字鏈接獲得調試的詳細資訊。
3. struts.xml
<?xml version="1.0" encoding="UTF-8" ?> <!DOCTYPE struts PUBLIC "-//Apache Software Foundation//DTD Struts Configuration 2.0//EN" "http://struts.apache.org/dtds/struts-2.0.dtd"> <struts> <constant name="struts.devMode" value="true" /> <package name="default" namespace="/" extends="struts-default"> <action name="debugTagAction" class="com.xuhuhu.common.action.DebugTagAction" > <result name="success">pages/debug.jsp</result> </action> </package> </struts>
4. 示例
http://localhost:8080/struts2debugtag/debugTagAction.action
在流覽器中打開上面的網址,輸出結果如下:
參考
下載代碼 - http://pan.baidu.com/s/1gdEvJGZ
上一篇:
Struts2 <s:date>標籤示例
下一篇:
Struts2 <s:include>標籤示例