struts标签

struts标签

  1. struts标签
    1.1 通用标签
    1.1.1 数据标签
    property
    set
    scope=“action”,action=request+actionContext
    push
    修改页面
    param
    blue

    注1:它是子标签
    注2:url/action
    date
    java.text.SimpleDateFormat/DecimalFormat
    debug
    url/param/a(重要~用来生成url链接的)

       action
    

    1.1.2 控制标签
    iterator/if/elseif/else

1.2 UI标签
1.2.1 表单标签
主题:xhtml/simple

1.2.2 非表单标签
比如 a

简单的写了一下
现在jsp里面随便弄两个a标签用来条页面的

<h1>struts常用标签</h1>
	<a href="${pageContext.request.contextPath }/sy/tagAction.action?num1=20&cal2.num1=1&result=250">测试8</a>
	
	<h1>struts表单标签</h1>
	<a href="demo4.jsp">测试9</a>

配置好web.xml和struts-sy.xml

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://xmlns.jcp.org/xml/ns/javaee" xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd" id="WebApp_ID" version="3.1">
  <filter>
    <filter-name>struts2</filter-name>
    <filter-class>org.apache.struts2.dispatcher.filter.StrutsPrepareAndExecuteFilter</filter-class>
  </filter>
  <filter-mapping>
    <filter-name>struts2</filter-name>
    <url-pattern>/*</url-pattern>
  </filter-mapping>
</web-app>

struts-sy.xml

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE struts PUBLIC
	"-//Apache Software Foundation//DTD Struts Configuration 2.5//EN"
	"http://struts.apache.org/dtds/struts-2.5.dtd">
	
<struts>
<!-- 
namespace:在内存中划分具体的控件
name:给包取个名字
 -->
	<package name="sy" extends="base" namespace="/sy">
		 <action name="tagAction" class="com.zking.three.TagAction">
			<result name="demo3">/demo3.jsp</result>
		 </action>
		 
	</package>
</struts>

通用标签
记得导库 <%@ taglib uri="/struts-tags" prefix=“s”%>

<%@page import="java.util.Date"%>
<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
    <%@ taglib uri="/struts-tags" prefix="s"%>
<!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>通用标签</title>
</head>
<body>
	 <h3 style="color: red;">数据标签</h3>
          <h3>set</h3>
          <!-- 在ognl上下文的根对象中取result值,赋值给test1 -->
          <s:set var="test1" value="result"></s:set>
          ${test1 }
          <h3>property</h3>
          <!-- 取栈顶 -->
          <s:property/>---
          <!-- 取根对象最上面的属性 -->
           <s:property value="num1"/>---
           <!-- 取根对象的cal2的属性num1 -->
          <s:property value="cal2.num1"/>---
           <!-- 取非根对象的cal2的num1属性值 -->
          <s:property value="#request.cal2.num1"/>
          
          <h3>push</h3>
          <!-- push就是将你所需要的值放到栈顶,便于获取 -->
          <s:property/>
          <s:push value="result">
          	<s:property/>
          </s:push>
          <s:property/>
          
          <h3>action</h3>
          <!-- action通常用来请求后台,获取初始化数据的 -->
          <s:action name="tagAction" namespace="/sy" var="test2"></s:action>
          <s:property value="#test2.cal2"/>
          
          <h3>url</h3>
          <!-- url标签是为了生成地址所用,注意与a标签区分 -->
          <s:url namespace="/sy" action="tagAction" var="test3" ></s:url>
           <s:property value="test3"/>
           <a href='<s:property value="test3"/>'>aaa</a>
           <s:a href="%{#test3}">bbb</s:a>
           
          <h3>param</h3>
          <!-- param两种赋值方式:1、ognl表达式,2、字符串 -->
          <s:url namespace="/sy" action="tagAction" var="test4">
          	<s:param name="test5">aa</s:param>
          	<s:param name="test6" value="num1"></s:param>
          </s:url>
          <s:property value="#test4"/>
          
          <h3>date</h3>
          <%
	          request.setAttribute("currentDate", new Date());
	          request.setAttribute("score", new Integer(70));
	          request.setAttribute("names", new String[]{"ww","zs","ls"});
          %>
          <s:date name="#request.currentDate" format="yyyy-MM-dd"/>
          <h3>debug</h3>
          <s:debug/>
          
          
   	 <h3 style="color: red;">控制标签</h3>
   	 	<h3>iterator/if/elseif/else</h3>
   	 	<ul>
   	 	<s:iterator var="v" value="#request.names">
          <li>
          	<s:property value="v"/>
          </li>
          </s:iterator>
   	 	</ul>
          
          
          <s:if test="#request.score>80">
          	a
          </s:if>
          <s:elseif test="#request.score>60">
          b
          </s:elseif>
		<s:else>c</s:else>
          
</body>
</html>

表单标签

<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
    <%@ taglib uri="/struts-tags" prefix="s" %>
<!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>表单标签</title>
</head>
<body>
	crud详细讲解
	 <h3 style="color: red;">表单标签</h3>
          <h3>form</h3>
          <h3>textfield</h3>
          <h3>radio</h3>
          <h3>select</h3>
          <h3>textarea</h3>
          <h3>hidden</h3>
          <h3>submit</h3>
          
          <s:form namespace="" action="">
          	<s:textfield label="姓名" name="uname"></s:textfield>
          	<%-- <s:radio list="{'男','女'}" lable="性别" name="usex" value="'男'"></s:radio> --%>
          	<s:radio list="#{1:'男',2:'女'}" label="性别" name="usex" value="1"></s:radio>
          	<s:select label="部门选择" list="#{1:'财务部',2:'公关部',3:'人事部' }" name="dept"></s:select>
          	<!-- 单选复选框 往后台传值是boolean类型-->
          	<s:checkbox name="cb" label="哈哈"></s:checkbox>
          	<!-- 多选复选框 -->
          	<s:checkboxlist name="cbl" label="爱好" list="#{1:'基佬翔',2:'蹲坑',3:'蹲茅坑' }"></s:checkboxlist>
				<s:textarea label="简介" name="jj"></s:textarea>          	
          	<s:hidden name="hh" value="11111"></s:hidden>
          	
          </s:form>
          
          
</body>
</html>
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值