struts2的s:debug标签详解及其案例分析

导读:本篇文章讲解 struts2的s:debug标签详解及其案例分析,希望对大家有帮助,欢迎收藏,转发!站点地址:www.bmabk.com

在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文件

页面效果如下

struts2的s:debug标签详解及其案例分析

点击debug然后显示如下

struts2的s:debug标签详解及其案例分析

很明显从url可以看出,我们传了两个参数username和password,我们可以在Value Stack Contents中看到

从案例中我们可以得出,它提供的是Struts ValueStack Debug ..也就是说,都是struts2的值栈(就是各个值的信息).

版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 举报,一经查实,本站将立刻删除。

文章由极客之音整理,本文链接:https://www.bmabk.com/index.php/post/15240.html

(0)
小半的头像小半

相关推荐

极客之音——专业性很强的中文编程技术网站,欢迎收藏到浏览器,订阅我们!