Struts2数据标签:<s:property><s:a><s:debug><s:include><s:param>等

  • 内容
  • 评论
  • 相关

数据标签主要用于提供各种和数据访问相关的功能,如输出信息和显示调试信息等。常用的数据标签有 <s:property>、<s:a>、<s:debug>、<s:include> 和 <s:param> 等。

<s:property>标签

<s:property> 标签的作用是输出指定的值,通常输出的是 value 属性指定的值,<s:property> 标签的属性及属性说明如下。

  • value:可选属性,指定需要输出的属性值,如果没有指定该属性,则默认输出 ValueStack 栈顶的值(关于值栈内容会在后面教程中进行讲解)。
  • id:可选属性,指定该元素的标识。
  • default:可选属性,如果要输出的属性值为 null,则显示 default属性的指定值。
  • escape:可选属性,指定是否忽略 HTML 代码。默认值是 true,即忽略输出值中的 HTML 代码。

为了使读者更好地掌握 <s:property> 标签的使用,下面编写案例进行演示。在项目的 WebContent 目录下创建一个名称为 propertyTags.jsp 的文件,编辑后如下所示。

<%@ page language="java" contentType="text/html; charset=utf-8"
    pageEncoding="utf-8"%>
<%@taglib prefix="s" uri="/struts-tags" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>property标签</title>
</head>
<body>
    输出字符串:
    <s:property value="'this is a string'"/><br/>
    输出默认值:
    <s:property value="" default="default_value"/><br/>
    忽略HTML代码:
    <s:property value="'<h2>www.w3school.com.cn</h2>'" escape="true"/><br/>
    不忽略HTML代码:
    <s:property value="'<h2>www.w3school.com.cn</h2>'" escape="false"/><br/>
</body>
</html>

上述代码中,分别对 <s:property> 标签的 value、default 和 escape 属性的使用进行了演示。启动项目后,在浏览器的地址栏中输入地址 http://localhost:8080/struts2Demo04/propertyTags.jsp 访问 propertyTags.jsp,浏览器的显示结果如图 1 所示。

property标签的输出
图 1  property标签的输出

本文标题:Struts2数据标签:<s:property><s:a><s:debug><s:include><s:param>等

本文地址:http://www.hosteonscn.com/5751.html

评论

0条评论

发表评论

邮箱地址不会被公开。 必填项已用*标注