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的更多相关文章

  1. Vue - 内部指令

    1.插值 A:<span>TEXT:{{text}}</span> {{text}}会被相应的数据类型text属性值替换,当text值改变时候,文本中的值也会相应的发生变化 B ...

  2. vue学习笔记之v-for与-repeat

    今天看到一个v-repeat的例子 <body> <ul id="tags"> <li v-repeat="tags"> { ...

  3. matplotlib读取csv文件

    一,从本地加载csv文件 from matplotlib import pyplot as pltimport numpy as npimport csv#用来正常显示中文标签plt.rcParams ...

  4. BERT-Pytorch版本代码pipline梳理

    最近在做BERT的fine-tune工作,记录一下阅读项目https://github.com/weizhepei/BERT-NER时梳理的训练pipline,该项目基于Google的Transfor ...

  5. 基于MVC4+EasyUI的Web开发框架经验总结(1)-利用jQuery Tags Input 插件显示选择记录

    最近花了不少时间在重构和进一步提炼我的Web开发框架上,力求在用户体验和界面设计方面,和Winform开发框架保持一致,而在Web上,我主要采用EasyUI的前端界面处理技术,走MVC的技术路线,在重 ...

  6. Helpers\Tags

    Helpers\Tags The tags helper is a collection of useful methods: Tags::clean($data) Clean function to ...

  7. jQuery Tags Input 插件显示选择记录

    利用jQuery Tags Input 插件显示选择记录 最近花了不少时间在重构和进一步提炼我的Web开发框架上,力求在用户体验和界面设计方面,和Winform开发框架保持一致,而在Web上,我主要采 ...

  8. (转)基于MVC4+EasyUI的Web开发框架经验总结(1)-利用jQuery Tags Input 插件显示选择记录

    http://www.cnblogs.com/wuhuacong/p/3667703.html 最近花了不少时间在重构和进一步提炼我的Web开发框架上,力求在用户体验和界面设计方面,和Winform开 ...

  9. 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 ...

  10. 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 ...

随机推荐

  1. 开启Win7多用户登录远程桌面

    原文链接: http://blog.sina.com.cn/s/blog_7e5da5b101014fc4.html 多用户登陆破解:(支持win7 x86 & win7x64)在 Windo ...

  2. bootstrap 多元素共用 popover

    <div class="popover fade bottom in small" role="tooltip" id="gPopover&qu ...

  3. RichTextBox指定全部文字显示不同颜色及部分文字高亮颜色显示

    指定全部显示不同颜色: public void SetTextContent(string text, ColorEnum color) { Font font = , FontStyle.Bold) ...

  4. unity 设置屏幕尺寸

    在PlayerSettings中将web player的screen size设成600x900后,需要在Game视图下拉菜单中选Web(600x900),Game视图才能显示成我们设定的尺寸.

  5. 【JUnit4.10源码分析】5.2 Rule

    标注@Rule TestRule是一个工厂方法模式中的Creator角色--声明工厂方法. package org.junit.rules; import org.junit.runner.Descr ...

  6. WIN10中运行ASP出错

    一个项目用ASP做的,想在WIN中IIS建立网站部署起来,开始怎么弄都不行,运行总是出现那句英文,后来才知道要在IIS中的网站的ASP选项中的调试属性中把发送错误到到浏览器打开,这样才能发现程序报错, ...

  7. css 样式使用方法的累积

    我们直接看样例然后在来解释使用方法. <!DOCTYPE html> <html> <head> <style> input[type="ch ...

  8. 完美解决 IOS系统safari5.0 浏览器页面布局iframe滚动栏失效问题

    在iframe外层包一层div,加入例如以下样式: style="-webkit-overflow-scrolling:touch;overflow:auto;" 代码例如以下: ...

  9. ThinkPad 预装win8换win7(软激活)

    今天晚上有人叫我给他装系统,没错!这就是计算机专业的拿手技能(维修学院重装系统专业Win7系统班^-^). 一拿手上,是lenovo的ThinkPad E430型号,预装的系统是win8,由于win8 ...

  10. EXCEL多列名称组合成一列名称