三大标签:

1.JSP:脚本,为了替代servlet,已过时

2.JSTL:标准标签库(core、format、sql、xml),还未淘汰的只有core库

3.Struts2标签库:由Struts2开发团队开发,功能更加强大

struts2标签分为:普通标签、UI标签

普通标签分:控制标签,数据标签

UI标签分:表单标签,非表单标签

准备一些数据:

        List<String> list = new ArrayList<>();
list.add("tom");
list.add("jerry");
list.add("jack");
list.add("rose"); ActionContext.getContext().put("list", list);

普通标签示例:

<%@ 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>Insert title here</title>
</head>
<body>
<!-- 遍历标签 iterator -->
<!-- ------------------------------------- -->
<s:iterator value="#list" >
<s:property /><br>
</s:iterator>
<!-- ------------------------------------- --><hr>
<s:iterator value="#list" var="name" >
<s:property value="#name" /><br>
</s:iterator>
<!-- ------------------------------------- --><hr>
<s:iterator begin="1" end="100" step="1" >
<s:property />|
</s:iterator>
<!-- ------------------if else elseif标签------------------- --><hr> <s:if test="#list.size()==4">
list长度为4!
</s:if>
<s:elseif test="#list.size()==3">
list长度为3!
</s:elseif>
<s:else>
list长度不为3也不为4!
</s:else> <!-- ------------------property 配合ognl表达式页面取值 ------------------- --><hr> <s:property value="#list.size()" />
<s:property value="#session.user.name" /> </body>
</html>

表单标签(不常用):

    <!-- struts2表单标签 -->
<!-- 好处1: 内置了一套样式. -->
<!-- 好处2: 自动回显,根据栈中的属性 -->
<!-- theme:指定表单的主题
xhtml:默认
simple:没有主题
-->
<s:form action="Demo3Action" namespace="/" theme="xhtml" >
<s:textfield name="name" label="用户名" ></s:textfield>
<s:password name="password" label="密码" ></s:password>
<s:radio list="{'男','女'}" name="gender" label="性别" ></s:radio>
<s:radio list="#{1:'男',0:'女'}" name="gender" label="性别" ></s:radio>
<s:checkboxlist list="#{2:'抽烟',1:'喝酒',0:'打游戏'}" name="habits" label="爱好" ></s:checkboxlist>
<s:select list="#{2:'大专',1:'本科',0:'硕士'}" headerKey="" headerValue="---请选择---" name="edu" label="学历" >
</s:select>
<s:file name="photo" label="近照" ></s:file>
<s:textarea name="desc" label="个人简介" ></s:textarea>
<s:submit value="提交" ></s:submit>
</s:form> <s:actionerror/>

Action:

package tag;

import com.opensymphony.xwork2.ActionSupport;

public class Demo3Action extends ActionSupport {

    private String name;
public String execute() throws Exception {
System.out.println(name); this.addActionError("错误"); return SUCCESS;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
} }

struts2框架学习笔记7:struts2标签的更多相关文章

  1. j2ee开发之struts2框架学习笔记

    Struts2框架技术重点笔记 1.Struts2 是在webwork基础上发展而来. 2.Struts2 不依赖struts API和 servlet API 3.Struts2提供了拦截器,表现层 ...

  2. struts2框架学习笔记1:搭建测试

    Servlet是线程不安全的,Struts1是基于Servlet的框架 而Struts2是基于Filter的框架,解决了线程安全问题 因此Struts1和Struts2基本没有关系,只是创造者取名问题 ...

  3. Struts2框架学习笔记--strtus2初识

    struts2概述: 1.struts2框架应用于javaEE三层结构中的Web层框架 2.struts2框架是在struts1和webwork基础之上发展的全新框架(脱胎换骨 ,用法完全不一样)ps ...

  4. Struts2框架学习笔记1

    1,框架概述 1.1,什么是框架(了解) 将一些重复性的代码进行封装,简化程序员的编程操作,可以使得程序员在编码中把更多的精力放到业务需求的分析和理解上面,相当于一个半成品软件. 1.2,三大框架(掌 ...

  5. struts2框架学习笔记5:OGNL表达式

    OGNL取值范围分两部分,root.Context两部分 可以放置任何对象作为ROOT,CONTEXT中必须是Map键值对 示例: 准备工作: public void fun1() throws Ex ...

  6. Struts2框架学习第一章——Struts2概述

    本章要点 —  Web应用的发展 —  Model 1和Model 2 —  MVC思想 —  MVC模式的优势 — 常用MVC框架及其特征 —  Struts 1的基本结构及其存在的问题 —  We ...

  7. struts2框架学习笔记2:配置详解

    核心配置文件: <?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE struts PUBLIC ...

  8. 02 Struts2框架----学习笔记2(了解一下,已过时)

    1.*号通配符优化struts.xml代码 创建一个UserAction的动作类 package action; import com.opensymphony.xwork2.ActionSuppor ...

  9. struts2框架学习笔记6:拦截器

    拦截器是Struts2实现功能的核心部分 拦截器的创建: 第一种: package interceptor; import com.opensymphony.xwork2.ActionInvocati ...

随机推荐

  1. 深入剖析GPU Early Z优化

    最近在公司群里同事发了一个UE4关于Mask材质的优化,比如在场景中有大面积的草和树的时候,可以在很大程度上提高效率.这其中的原理就是利用了GPU的特性Early Z,但是它的做法跟我最开始的理解有些 ...

  2. js原型继承四步曲

    <sctript> //1.创建父类 function Parent(){ this.name = name; } Parent.prototype.age = 20; //2.创建子类 ...

  3. Redis在linux上的配置

    一.安装gcc  1.Redis在linux上的安装首先必须先安装gcc,这个是用来编译redis的源文件的.首先需要先切换的到root用户 2.然后开始安装gcc: yum install gcc- ...

  4. 大数据入门到精通10--spark rdd groupbykey的使用

    //groupbykey 一.准备数据val flights=sc.textFile("data/Flights/flights.csv")val sampleFlights=sc ...

  5. Selenium Webdriver元素定位的八种常用方式(转载)

    转载自 https://www.cnblogs.com/qingchunjun/p/4208159.html 在使用selenium webdriver进行元素定位时,通常使用findElement或 ...

  6. Full authentication is required to access this resource

    参考 https://www.jianshu.com/p/d10e0cee4adb security.basic.enabled=false

  7. FortiGate部分用户上网慢,丢包严重

    1.现状: 如图,出口internet有2条联通线路分别为liant_218和liant_61,在防火墙上使用WAN LLB,基于源IP: 2.现象: 使用liant_218的用户上网正常,使用lia ...

  8. (转)css3实现load效果

    本文转自:https://www.cnblogs.com/jr1993/p/4625628.html 谢谢作者 注:gif图片动画有些卡顿,非实际效果! 第一种效果: 代码如下: <div cl ...

  9. 396. Rotate Function 移动加权求和,取最大值

    [抄题]: Given an array of integers A and let n to be its length. Assume Bk to be an array obtained by ...

  10. [leetcode]152. Maximum Product Subarray最大乘积子数组

    Given an integer array nums, find the contiguous subarray within an array (containing at least one n ...