Struts tags--Data tags
struts tags详解之<s:bean>
Description
Bean标签,当然需要一个JavaBean。它的属性值的操作是经由Bean标签中的参数属性来进行赋值。当然,它还有一个id属性可以进行赋值,这样就可以在上下文中使用这个Bean
如果在BeanTag中设置了var属性值,那么它将把实例化后的bean放入到stack's Context中。
Parameters
|
名称 |
必需 |
数据类型 |
描述 |
|
Id |
False |
String |
已弃用,var代替 |
|
Name |
true |
String |
bean的实例化类的名称(必须遵循JavaBean规范) |
|
Var |
False |
String |
用于引用到Value Stack中的值的名称 |
Examples
1 <-- in jsp form -->
2 <s:bean name="org.apache.struts2.example.counter.SimpleCounter" var="counter">
3 <s:param name="foo" value="BAR" />
4 The value of foot is : <s:property value="foo"/>, when inside the bean tag
5 </s:bean>
这个例子实例化了一个名叫SimpleCounter的bean,并设置foo属性(setFoo(‘BAR’))。然后将SimpleCounter对象压入值栈(Valuestack)中,这意味着我们可以调用property tag的访问方法(getFoo())来得到它的值。
在上面的例子中,id的属性值已经设为counter,这意味着SimpleCounter对象压入值栈(Valuestack)后可以通过如下标签来访问它:
1 <-- jsp form -->
2 <s:property value="#counter" />
1.WebRoot/pages/dataTags/beanTag.jsp,代码如下:
1 <%@ page contentType="text/html; charset=GBK" %>
2 <%@ taglib prefix="s" uri="/struts-tags" %>
3 <html>
4 <head>
5 <title>Bean Tag 示例</title>
6 </head>
7 <body>
8 <h2>Bean Tag 示例</h2>
9 <s:bean name="com.sterning.companyName" id="uid">
10 <s:param name="name">sterning</s:param>
11 <s:property value="%{name}" /><br>
12 </s:bean>
13 </body>
14 </html>
其关联的JavaBean是com.sterning.companyName,同时参数name赋值为sterning。
2.首先创建Action进行跳转, src/com/sterning/beanTag.java,代码如下:
package com.sterning;
import com.opensymphony.xwork2.ActionSupport;
public class beanTag extends ActionSupport {
public String execute() throws Exception{
return SUCCESS;
}
}
然后创建JavaBean,src/com/sterning/companyName.java,代码如下:
1 package com.sterning;
2 public class companyName {
3 private String name;
4 public void setName(String name){
5 this.name =name ;
6 }
7 public String getName(){
8 return name;
9 }
10
11 }
3.Struts.xml的配置
这里配置很简单,与前面的例子差不多。
1 <action name="beanTag" class="com.sterning.beanTag">
2 <result name="success">/pages/dataTags/beanTag.jsp</result>
3 </action>
运行结果如下:

struts2 tags详解之<s:property>
Description
用于获取一个属性的值。Property顾名思义,可以与<s:bean>标签结合使用,一个是给bean赋值,一个是从bean中读取值。
Examples
<s:push value="myBean">
<!-- Example 1: -->
<s:property value="myBeanProperty" />
<!-- Example 2: -->TextUtils
<s:property value="myBeanProperty" default="a default value" />
</s:push>
result:
Example 1 prints the result of myBean's getMyBeanProperty() method.
Example 2 prints the result of myBean's getMyBeanProperty() method and if it is null, print 'a default value' instead.
Struts2 tags详解之<s:set>
Set标签比较简单。Set标签用户将某一值赋给某一变量,因此,任何对该项值的引用都可以通过该变量来得到该值。该变量的活动范围可自定义。如下例中,定义一健/值对,对值的引用,直接引用值就可以。。请看示例
1.WebRoot/pages/dataTags/ setTag.jsp
<%@ page contentType="text/html; charset=GBK" %>
<%@ taglib prefix="s" uri="/struts-tags" %>
<html>
<head>
<title>Set Tag 示例</title>
</head>
<body>
<h2>Set Tag 示例</h2>
<s:set name="technologyName" value="%{'Java'}"/>
Technology Name: <s:property value="#technologyName"/>
</body>
</html>
2.Struts.xml配置
<action name="setTag">
<result>/pages/dataTags/setTag.jsp</result>
</action>
3.运行效果

Struts tags--Data tags的更多相关文章
- Vue - 内部指令
1.插值 A:<span>TEXT:{{text}}</span> {{text}}会被相应的数据类型text属性值替换,当text值改变时候,文本中的值也会相应的发生变化 B ...
- vue学习笔记之v-for与-repeat
今天看到一个v-repeat的例子 <body> <ul id="tags"> <li v-repeat="tags"> { ...
- matplotlib读取csv文件
一,从本地加载csv文件 from matplotlib import pyplot as pltimport numpy as npimport csv#用来正常显示中文标签plt.rcParams ...
- BERT-Pytorch版本代码pipline梳理
最近在做BERT的fine-tune工作,记录一下阅读项目https://github.com/weizhepei/BERT-NER时梳理的训练pipline,该项目基于Google的Transfor ...
- 基于MVC4+EasyUI的Web开发框架经验总结(1)-利用jQuery Tags Input 插件显示选择记录
最近花了不少时间在重构和进一步提炼我的Web开发框架上,力求在用户体验和界面设计方面,和Winform开发框架保持一致,而在Web上,我主要采用EasyUI的前端界面处理技术,走MVC的技术路线,在重 ...
- Helpers\Tags
Helpers\Tags The tags helper is a collection of useful methods: Tags::clean($data) Clean function to ...
- jQuery Tags Input 插件显示选择记录
利用jQuery Tags Input 插件显示选择记录 最近花了不少时间在重构和进一步提炼我的Web开发框架上,力求在用户体验和界面设计方面,和Winform开发框架保持一致,而在Web上,我主要采 ...
- (转)基于MVC4+EasyUI的Web开发框架经验总结(1)-利用jQuery Tags Input 插件显示选择记录
http://www.cnblogs.com/wuhuacong/p/3667703.html 最近花了不少时间在重构和进一步提炼我的Web开发框架上,力求在用户体验和界面设计方面,和Winform开 ...
- Building Applications with Force.com and VisualForce (DEV401) (二十):Visualforce Pages: Visualforce Componets (Tags)
Dev401-021:Visualforce Pages: Visualforce Componets (Tags) Module Agenda1.Tag Basics2.Tag Bindings T ...
- Building Applications with Force.com and VisualForce(Dev401)(十九):Visualforce Pages: Visualforce Componets (Tags)
Dev401-020:Visualforce Pages: Visualforce Componets (Tags) Module Agenda1.Tag Basics2.Tag Bindings T ...
随机推荐
- 基于KWIC 的keyword匹配算法(管道+过滤器模式下实现)
以下是基于KWIC 的keyword匹配算法(管道+过滤器模式下实现) 关键部分的管道+过滤器 软件体系下的实现, 在非常多的keyword搜索平台都使用了这一 循环移位+排序输出的 keyword匹 ...
- VC获得window操作系统版本号, 获取操作系统位数
原文链接: http://www.greensoftcode.net/techntxt/2014315195331643021849 #include <Windows.h>include ...
- Python acos() 函数
描述 acos() 返回x的反余弦弧度值. 语法 以下是 acos() 方法的语法: import math math.acos(x) 注意:acos()是不能直接访问的,需要导入 math 模块,然 ...
- gulp#4.0
gitbook教程: https://dragon8github.gitbooks.io/gulp-webpack/content/an-zhuang-gulp-4-0.html gulpfile.j ...
- unity 获得父子节点
与常识不同,unity中获得父子节点需要通过transform.即先获得父/子节点的transform,然后再通过父/子节点的transform获得父/子节点. 获得父节点gameObject: Ga ...
- cocos2dx 3.3 getParentToNodeTransform bug
cocos2dx 3.3中getParentToNodeTransform实现如下: const Mat4& Node::getParentToNodeTransform() const { ...
- C语言:冒泡排序法:将若干字符串按字母顺序(由小到大)排序输出
#include<stdio.h> #include<string.h> void sort(char *a[]); void print(char *a[]); int ma ...
- HDU 4968 Improving the GPA(dp)
HDU 4968 Improving the GPA 题目链接 dp.最大最小分别dp一次,dp[i][j]表示第i个人,还有j分的情况,分数能够减掉60最为状态 代码: #include <c ...
- sed匹配两种重要思想
1,sed匹配两种重要思想 屏蔽思想:遮住不想要的 挑出思想:遮住所有,挑出想要的. 2,实例 屏蔽思想: [root@lanny ~]# sed -n '2p' file.txt |sed -r ' ...
- ORACLE 11G在存储过程里面遍历游标, 调用job任务定时运行
ORACLE存储过程里游标遍历.调用job定时运行 1,第一种使用For 循环 for循环是比較简单有用的方法. 首先.它会自己主动open和close游标.攻克了你忘记打开或关闭游标的烦恼. 其次, ...