在Struts2在 <s:debug> 标签是一个非常有用的调试标记输出“值栈”的内容,并在网页中“堆栈上下文”的详细信息。
它提供的是Struts ValueStack Debug ..也就是说,都是struts2的值栈(就是各个值的信息)..
这个值栈又分为两种.Value Stack Contents 和 Stack Context .
(1).Value Stack Contents 里面的信息我们可以用 <s:property value="key"> 这样来直接访问.
(2) Stack Context 里面的信息我们可以 <s:property value="#key">这样来访问
看下面的例子.
先创建一个user实体类
package com.cszy.entity;
public class User {
private String username;
private String password;
public String getUsername() {
return username;
}
public void setUsername(String username) {
this.username = username;
}
public String getPassword() {
return password;
}
public void setPassword(String password) {
this.password = password;
}
}
然后创建一个action
package com.cszy.valuestack;
import com.cszy.entity.User;
import com.opensymphony.xwork2.ActionSupport;
import com.opensymphony.xwork2.ModelDriven;
public class ValuestackAction4 extends ActionSupport implements ModelDriven<User>{
//使用ModelDriven接口接收参数(模型驱动)
private User user = new User();
@Override
public User getModel() {
return this.user;
}
@Override
public String execute() throws Exception {
// TODO Auto-generated method stub
return SUCCESS;
}
}
编写一个jsp页面
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ taglib uri="/struts-tags" prefix="s"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<base href="<%=basePath%>">
<title>My JSP 'valuestack.jsp' starting page</title>
<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="This is my page">
<!--
<link rel="stylesheet" type="text/css" href="styles.css">
-->
</head>
<body>
<h3>s:debug标签可以在html页面上查看值栈内容</h3>
<s:debug></s:debug>
</body>
</html>
记得配置struts.xml文件
页面效果如下
点击debug然后显示如下
很明显从url可以看出,我们传了两个参数username和password,我们可以在Value Stack Contents中看到
从案例中我们可以得出,它提供的是Struts ValueStack Debug ..也就是说,都是struts2的值栈(就是各个值的信息).