`
IT阿狸
  • 浏览: 67162 次
  • 性别: Icon_minigender_1
  • 来自: 广州
社区版块
存档分类
最新评论

Struts2中使用<sx: />标签实现组合查询和带分页的例子

阅读更多

一、这是SSH框架下的demo:

 TestCustomer.zip

 

二、例子界面



 

 三、然后建立一JavaBean类用来封装查询条件

package util;
/**
 * 客户信息关系表的查询属性
 * @author miao
 *
 */
public class SearchProperties {
	
	private int custNo;
	private String custName;
	private String custRegion;
	private String custManagerName;
	private String custLevelLabel;
	
	public SearchProperties() {
		super();
	}
	
	public SearchProperties(String custName, String custRegion,
			String custManagerName, String custLevelLabel) {
		super();
		this.custName = custName;
		this.custRegion = custRegion;
		this.custManagerName = custManagerName;
		this.custLevelLabel = custLevelLabel;
	}

	public SearchProperties(int custNo, String custName, String custRegion,
			String custManagerName, String custLevelLabel) {
		super();
		this.custNo = custNo;
		this.custName = custName;
		this.custRegion = custRegion;
		this.custManagerName = custManagerName;
		this.custLevelLabel = custLevelLabel;
	}

	public int getCustNo() {
		return custNo;
	}

	public void setCustNo(int custNo) {
		this.custNo = custNo;
	}

	public String getCustName() {
		return custName;
	}

	public void setCustName(String custName) {
		this.custName = custName;
	}

	public String getCustRegion() {
		return custRegion;
	}

	public void setCustRegion(String custRegion) {
		this.custRegion = custRegion;
	}

	public String getCustManagerName() {
		return custManagerName;
	}

	public void setCustManagerName(String custManagerName) {
		this.custManagerName = custManagerName;
	}

	public String getCustLevelLabel() {
		return custLevelLabel;
	}

	public void setCustLevelLabel(String custLevelLabel) {
		this.custLevelLabel = custLevelLabel;
	}

}

 

 

四、dao接口

package dao;

import java.util.List;
import util.SearchProperties;
import entity.CstCustomer;

/**
 * 客户信息关系接口
 * 
 * @author Ali
 * 
 */
public interface CstCustomerDao {
	
	/**
	 * 查询总记录数
	 */
	public Integer findCount();
	
	/**
	 * 查询有条件的总记录数
	 */
	public Integer countCustomerByProperties(SearchProperties condition);
	
	/**
	 * 得到某条件的记录
	 */
	public List<CstCustomer> getCustomerByProperties(SearchProperties condition, int first, int max);
	
}

 

 

 五、daoImpl类

package dao.impl;

import java.util.List;
import org.hibernate.criterion.DetachedCriteria;
import org.hibernate.criterion.MatchMode;
import org.hibernate.criterion.Restrictions;
import org.springframework.orm.hibernate3.support.HibernateDaoSupport;
import util.SearchProperties;
import dao.CstCustomerDao;
import entity.CstCustomer;

/**
 * 客户信息关系实现类
 * 
 * @author Ali
 * 
 */
public class CstCustomerDaoImpl extends HibernateDaoSupport implements CstCustomerDao {

	/**
	 * 根据条件建立DetachedCriteria对象
	 * 
	 * @param condition
	 * @return
	 */
	public DetachedCriteria createCriterionByProperties(SearchProperties condition) {
		DetachedCriteria criteria = DetachedCriteria.forClass(CstCustomer.class);
		// 客户编号
		 if (condition.getCustNo() != 0) {
			 criteria.add(Restrictions.eq("custNo", condition.getCustNo()));
		 }
		// 客户名字
		if (null != condition.getCustName() && !"".equals(condition.getCustName())) {
			criteria.add(Restrictions.ilike("custName", condition.getCustName(),
					MatchMode.ANYWHERE));
		}
		// 地区
		if (null != condition.getCustRegion() && !"".equals(condition.getCustRegion())) {
			criteria.add(Restrictions.ilike("custRegion", condition.getCustRegion(),
					MatchMode.ANYWHERE));
		}
		// 客户经理
		if (null != condition.getCustManagerName() && !"".equals(condition.getCustManagerName())) {
			criteria.add(Restrictions.ilike("custManagerName", condition.getCustManagerName(),
					MatchMode.ANYWHERE));
		}
		// 客户等级
		if (null != condition.getCustLevelLabel() && !"".equals(condition.getCustLevelLabel())) {
			criteria.add(Restrictions.eq("custLevelLabel", condition.getCustLevelLabel()));
		}
		return criteria;
	}

	/**
	 * 查询总记录数
	 */
	public Integer findCount() {
		return super.getHibernateTemplate().loadAll(CstCustomer.class).size();
	}

	/**
	 * 得到某条件的记录
	 * 
	 * @param condition
	 * @param first
	 * @param max
	 * @return
	 */
	@SuppressWarnings("unchecked")
	public List<CstCustomer> getCustomerByProperties(SearchProperties condition, int first, int max) {
		DetachedCriteria detachedCriteria = createCriterionByProperties(condition);
		return super.getHibernateTemplate().findByCriteria(detachedCriteria, first, max);
	}

	/**
	 * 查询有条件的总记录数
	 */
	public Integer countCustomerByProperties(SearchProperties condition) {
		DetachedCriteria detachedCriteria = createCriterionByProperties(condition);
		return super.getHibernateTemplate().findByCriteria(detachedCriteria).size();
	}

}

 

 

 六、biz接口

package biz;

import java.util.List;
import util.SearchProperties;
import entity.CstCustomer;

/**
 * 客户信息关系业务接口
 * 
 * @author miao
 * 
 */
public interface CstCustomerBiz {
	
	/**
	 * 查询总记录数
	 */
	public Integer findCount();
	
	/**
	 * 查询有条件的总记录数
	 */
	public Integer countCustomerByProperties(SearchProperties condition);

	/**
	 * 得到某条件的记录
	 */
	public List<CstCustomer> getCustomerByProperties(SearchProperties condition, int first, int max);
	
}

 

 

七、bizImpl类

package biz.impl;

import java.util.List;
import util.SearchProperties;
import biz.CstCustomerBiz;
import dao.CstCustomerDao;
import entity.CstCustomer;

/**
 * 客户信息关系业务实现类
 * 
 * @author Ali
 * 
 */
public class CstCustomerBizImpl implements CstCustomerBiz {

	// 调用dao
	private CstCustomerDao cstCustomerDao;

	// set注入

	public void setCstCustomerDao(CstCustomerDao cstCustomerDao) {
		this.cstCustomerDao = cstCustomerDao;
	}

	/**
	 * 查询总记录数
	 */
	public Integer findCount() {
		return cstCustomerDao.findCount();
	}

	public Integer countCustomerByProperties(SearchProperties condition) {
		return cstCustomerDao.countCustomerByProperties(condition);
	}

	public List<CstCustomer> getCustomerByProperties(SearchProperties condition, int number, int size) {
		int first = (number - 1) * size;
		return cstCustomerDao.getCustomerByProperties(condition, first, size);
	}
	
}

 

 

八、第一个页面。用来显示查询条件和转跳至action

<%@ page language="java" contentType="text/html;charset=UTF-8"%>
<%@ taglib prefix="s" uri="/struts-tags"%>
<%@ taglib prefix="sx" uri="/struts-dojo-tags"%>
<%
	String path = request.getContextPath();
	String basePath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort() + path + "/";
%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
  <head>
		<base href="<%=basePath%>"/>
		<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
		<title>客户信息管理-查看全部客户信息</title>
		<link type="text/css" rel="stylesheet" href="css/style.css" />
		
		<sx:head />
	</head>
  <body>
  
  	<!-- 头部,查询条件 -->
    <div class="page_title">客户信息管理</div>
	<s:form method="post" action="search" id='sform' namespace="/" theme="simple">
		<div class="button_bar">
			<input type="reset" value="重置" />
			<sx:submit cssClass="common_button" type="button" name="search" value="查询" targets="divCustomer" />
		</div>
		<table class="query_form_table">
			<tr>
				<th>客户编号</th>
				<td>
					<s:textfield name="custNo" id="custNo" />
				</td>
				<th>名称</th>
				<td>
					<s:textfield name="custName" id="custName"/>
				</td>
				<th>地区</th>
				<td>
					<!-- key是值,value是显示 -->
					<s:select list="#{'':'全部','北京':'北京','华北':'华北','中南':'中南','东北':'东北','西部':'西部','上海':'上海' }" id="custRegion" name="custRegion"></s:select>
				</td>
			</tr>
			<tr>
				<th>客户经理</th>
				<td>
					<s:textfield name="custManagerName" id="custManagerName" />
				</td>
				<th>客户等级</th>
				<td>
					<s:select list="#{'':'全部','战略合作伙伴':'战略合作伙伴','合作伙伴':'合作伙伴','大客户':'大客户','普通客户':'普通客户' }" id="custLevelLabel" name="custLevelLabel"></s:select>
				</td>
				<th></th>
				<td></td>
			</tr>
		</table>
	</s:form>
	
	<!-- struts2 的??? -->
	<div class="data_list_table">
		<!-- 显示分页数据 -->
		<sx:div id="divCustomer" href="search.action">正在加载,请稍候...</sx:div>
	</div>
  </body>
</html>

 

 

九、第二个页面,用来显示数据和实现分页

<%@ page language="java" contentType="text/html;charset=UTF-8"%>
<%@ taglib prefix="s" uri="/struts-tags"%>
<%@ taglib prefix="sx" uri="/struts-dojo-tags"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%
	String path = request.getContextPath();
	String basePath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort() + path + "/";
%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
  <head>
    	<base href="<%=basePath%>"/>
    	<title>客户信息管理-查看全部客户信息</title>
	
		<sx:head />	
	
	<script src="script/common.js"></script>
	<link href="css/style.css" rel="stylesheet" type="text/css" />
  </head>
  
  <body>
  
  	<table class="data_list_table">
  		<tr>
			<th>序号</th>
			<th>客户编号</th>
			<th>名称</th>
			<th>地区</th>
			<th>客户经理</th>
			<th>客户等级</th>
			<th>操作</th>
		</tr>
		<c:if test="${customerList ne null}">
			<c:forEach items="${customerList}" var="customer" varStatus="row">
				<tr>
					<td class="list_data_number">${row.index+1 }</td>
					<td class="list_data_text">${customer.custNo }</td>
					<td class="list_data_ltext">${customer.custName }</td>
					<td class="list_data_text">${customer.custRegion }</td>
					<td class="list_data_text">${customer.custManagerName }</td>
					<td class="list_data_text">${customer.custLevelLabel }</td>
					<td class="list_data_op">
						<img onclick="location.href='edit.action?id=${customer.custNo }';" title="编辑" src="images/bt_edit.gif" class="op_button" />
						<img onclick="location.href='linkman.action?id=${customer.custNo}';" title="联系人" src="images/bt_linkman.gif" class="op_button" />
						<img onclick="location.href='activity.action?id=${customer.custNo}';" title="交往记录" src="images/bt_acti.gif" class="op_button" />
						<img onclick="location.href='orders.action?id=${customer.custNo }&name=${customer.custName}';" title="历史订单" src="images/bt_orders.gif" class="op_button" />
						<img onclick="location.href='delete.action?id=${customer.custNo}';" title="删除" src="images/bt_del.gif" class="op_button" />
					</td>
				</tr>
			</c:forEach>
		</c:if>
		<c:if test="${empty customerList}">
			<tr>
				<td colspan="7" align="center">
					<c:out value="暂无信息"></c:out>
				</td>
			</tr>
		</c:if>
		<!-- 分页 -->
		<tr>
			<th colspan="7" class="pager">
				<div class="pager">
					<!-- 不作显示 -->
					<s:url var="urlFirst" value="search.action">
						<s:param name="number" value="1" />
					</s:url>
					<s:url var="urlPrev" value="search.action">
						<s:param name="number" value="prev" />
					</s:url>
					<s:url var="urlNext" value="search.action">
						<s:param name="number" value="next" />
					</s:url>
					<s:url var="urlLast" value="search.action">
						<s:param name="number" value="total" />
					</s:url>
					<!-- 以上也是 -->
					共<s:property value="count" />条记录 每页3条
					第<s:property value="number" />页/共<s:property value="total" />页
					<sx:a href="%{urlFirst}" targets="divCustomer" formId="sform">第一页</sx:a>
					<sx:a href="%{urlPrev}" targets="divCustomer" formId="sform">上一页</sx:a>
					<sx:a href="%{urlNext}" targets="divCustomer" formId="sform">下一页</sx:a>
					<sx:a href="%{urlLast}" targets="divCustomer" formId="sform">最后一页</sx:a>
				</div>
			</th>
		</tr>
	</table>
  </body>
</html>

 

 

十、action的编写

package action;

import java.io.UnsupportedEncodingException;
import java.util.List;
import util.SearchProperties;
import biz.CstCustomerBiz;
import com.opensymphony.xwork2.ActionSupport;
import entity.CstCustomer;

/**
 * 客户管理的Action
 * 
 * @author miao
 * 
 */
public class CustomerManagerAction extends ActionSupport {

	/*
	 * 调用业务类
	 */

	private CstCustomerBiz cstCustomerBiz;// 客户信息关系

	/*
	 * 封装数据
	 */

	private List<CstCustomer> customerList;// 客户信息关系

	/*
	 * 分页需要的代码
	 */

	final static int PAGE_SIZE = 3;// 每页的记录数
	private int number;// 当前页
	private int total;// 总页面
	private int count;// 总记录数
	private int prev;// 上一页
	private int next;// 下一页

	/*
	 * 组合查询的条件
	 */

	private int custNo;
	private String custName;
	private String custRegion;
	private String custManagerName;
	private String custLevelLabel;

	/*
	 * 从页面传来的值
	 */

	private int id;// 根据id查询数据
	private String name;// 根据名字查询数据

	// set注入

	public void setCstCustomerBiz(CstCustomerBiz cstCustomerBiz) {
		this.cstCustomerBiz = cstCustomerBiz;
	}

	// getter/setter方法

	public static int getPageSize() {
		return PAGE_SIZE;
	}

	public int getCustNo() {
		return custNo;
	}

	public void setCustNo(int custNo) {
		this.custNo = custNo;
	}

	public String getCustName() {
		return custName;
	}

	public void setCustName(String custName) {
		this.custName = custName;
	}

	public String getCustRegion() {
		return custRegion;
	}

	public void setCustRegion(String custRegion) {
		this.custRegion = custRegion;
	}

	public String getCustManagerName() {
		return custManagerName;
	}

	public void setCustManagerName(String custManagerName) {
		this.custManagerName = custManagerName;
	}

	public String getCustLevelLabel() {
		return custLevelLabel;
	}

	public void setCustLevelLabel(String custLevelLabel) {
		this.custLevelLabel = custLevelLabel;
	}

	public String getName() {
		return name;
	}

	public void setName(String name) throws UnsupportedEncodingException {
		this.name = new String(name.getBytes("ISO-8859-1"), "utf-8");
	}

	public List<CstCustomer> getCustomerList() {
		return customerList;
	}

	public void setCustomerList(List<CstCustomer> customerList) {
		this.customerList = customerList;
	}

	public int getNumber() {
		return number;
	}

	public void setNumber(int number) {
		this.number = number;
	}

	public long getTotal() {
		return total;
	}

	public void setTotal(int total) {
		this.total = total;
	}

	public int getPrev() {
		return prev;
	}

	public void setPrev(int prev) {
		this.prev = prev;
	}

	public int getNext() {
		return next;
	}

	public void setNext(int next) {
		this.next = next;
	}

	public int getCount() {
		return count;
	}

	public void setCount(int count) {
		this.count = count;
	}

	public int getId() {
		return id;
	}

	public void setId(int id) {
		this.id = id;
	}

	/**
	 * 计算总页数
	 * 
	 * @param count 数据总记录数
	 * @param size 页面数据条数
	 */
	private int calcTotalPage(int count, int size) {
		return count % size == 0 ? count / size : count / size + 1;
	}

	/**
	 * 组合查询,带分页
	 */
	public String findByProperties() {
		SearchProperties condition = new SearchProperties();
		if ("".equals(custName) && "".equals(custRegion) && "".equals(custManagerName)
				&& "".endsWith(custLevelLabel)) {
			// 查询所有的记录条数
			count = cstCustomerBiz.findCount();
		} else {
			// 封装查询条件
			condition = new SearchProperties(custName, custRegion, custManagerName, custLevelLabel);
			// 查询有条件的总记录数
			count = cstCustomerBiz.countCustomerByProperties(condition);
		}
		// 计算总页数
		total = calcTotalPage(count, PAGE_SIZE);
		// 页面的处理
		if (number == 0) {
			number = 1;
		}
		prev = number - 1;
		next = number + 1;
		if (prev < 1) {
			prev = 1;
		}
		if (next > total) {
			next = total;
		}
		customerList = cstCustomerBiz.getCustomerByProperties(condition, number, PAGE_SIZE);
		return SUCCESS;
	}

}

 

 

十一、spring的配置文件

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:p="http://www.springframework.org/schema/p"
	xmlns:tx="http://www.springframework.org/schema/tx" xmlns:aop="http://www.springframework.org/schema/aop"
	xsi:schemaLocation="http://www.springframework.org/schema/beans
	 http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
	 http://www.springframework.org/schema/tx
	 http://www.springframework.org/schema/tx/spring-tx-2.5.xsd
	 http://www.springframework.org/schema/aop
	 http://www.springframework.org/schema/aop/spring-aop-2.5.xsd">

	<!-- 会话工厂 -->
	<bean id="sessionFactory"
		class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
		<property name="configLocation" value="classpath:hibernate.cfg.xml" />
	</bean>

	<!--注入dao类 -->
	<bean id="cstCustomerDao" class="dao.impl.CstCustomerDaoImpl">
		<description>客户信息关系接口</description>
		<property name="sessionFactory" ref="sessionFactory" />
	</bean>

	<!-- 注入biz -->
	<bean id="cstCustomerBiz" class="biz.impl.CstCustomerBizImpl">
		<description>客户信息关系业务</description>
		<property name="cstCustomerDao" ref="cstCustomerDao" />
	</bean>

	<!-- 注入action -->
	<bean id="customerManagerAction" class="action.CustomerManagerAction">
		<description>客户管理Action</description>
		<property name="cstCustomerBiz" ref="cstCustomerBiz" />
	</bean>

</beans>

 

 

十二、struts的配置文件

<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE struts PUBLIC "-//Apache Software Foundation//DTD Struts Configuration 2.1//EN" "http://struts.apache.org/dtds/struts-2.1.dtd">
<struts>

	<!-- 由spring管理 -->
	<constant name="stuts.objectFactory" value="spring" />

	<!-- 打开开发模式 -->
	<constant name="struts.devMode" value="true" />

	<package name="action" extends="struts-default" namespace="/">
		<action name="search" class="customerManagerAction" method="findByProperties">
			<result name="success">/listTrue.jsp</result>
			<result name="input">/listShow.jsp</result>
		</action>
	</package>

</struts>    

 

 

  • 大小: 54.5 KB
分享到:
评论

相关推荐

    Struts2中使用标签实现组合查询和带分页的例子

    在Struts2框架中,`&lt;sx:&gt;`标签是Struts2 XWork库的一部分,用于增强JSP页面的功能,提供更强大的数据绑定和表单处理能力。本篇将重点讲解如何利用`sx:`标签实现组合查询和带分页功能。 首先,让我们了解下Struts2的...

    struts2 标签使用

    ### Struts2 `&lt;s:if&gt;` 标签使用详解 #### 概述 Struts2 是一款基于 Java 的企业级 Web 应用框架,它利用了 MVC(Model-View-Controller)架构模式来帮助开发者构建可扩展、易于维护的 Web 应用程序。在 Struts2 中...

    Struts2中实现页面的跳转

    通过深入理解和正确配置上述元素,你可以有效地在Struts2框架中利用`&lt;jsp:forward/&gt;`标签实现页面的跳转,避免遇到“no found”的问题。同时,也要注意,在现代Web开发中,更多地使用`&lt;s:redirect/&gt;`标签进行重定向...

    Struts 1.XX <html:file>的使用

    Struts 1.XX 是一个基于MVC(Model-View-Controller)设计模式的Java Web框架,它在早期Web开发中被广泛使用。`&lt;html:file&gt;`是Struts提供的一个标签,主要用于处理用户在HTML表单中上传文件的功能。在Struts 1中,这...

    struts2<s:if>使用心得

    本篇文章将深入解析这段代码所涉及的关键知识点,并通过实际案例帮助理解如何使用Struts2中的`&lt;s:if&gt;`标签进行逻辑控制。 ### Struts2概述 Struts2是基于MVC设计模式的Web应用开发框架,它提供了丰富的标签库以及...

    struts标签(如<html:form>)

    关于STRUTS标签的一些详细说明。 如:&lt;html:form&gt;的说明。

    struts2实现分页

    通过上述内容可以看出,在 Struts2 中使用 `&lt;s:bean&gt;` 标签可以灵活地创建各种类型的 bean,并结合 `&lt;s:iterator&gt;` 标签实现高效的数据循环和分页功能。这种做法不仅简化了页面开发工作,还提高了程序的可读性和可...

    struts2 OGNL之&lt;s:property&gt;标签访问值栈(value stack)用法

    在这个主题中,我们将深入探讨OGNL(Object-Graph Navigation Language)以及如何通过`&lt;s:property&gt;`标签来访问Struts2中的值栈(Value Stack)。值栈是Struts2中一个核心的概念,它是一个存储用户请求数据和应用...

    Struts2 JSP中将list,set ,Map传递到Action然后<s:iterator>遍历(三十五)

    在JSP页面中,我们可以使用Struts2的标签库(例如`s:textfield`, `s:checkbox`, `s:select`等)来创建表单元素,并将这些元素与Action的属性绑定。对于集合类型,我们通常会在JSP中通过迭代器遍历并生成多个表单...

    Struts2标签列表及说明

    * &lt;s:generator&gt;:和 &lt;s:iterator&gt; 标签一起使用 H: * &lt;s:head&gt;:在 &lt;head&gt;&lt;/head&gt; 里使用,表示头文件结束 * &lt;s:hidden&gt;:隐藏值 I: * &lt;s:i18n&gt;:加载资源包到值堆栈 * &lt;s:include&gt;:包含一个输出,servlet ...

    struts2标签详解与实例

    这个例子展示了如何使用Struts2的`&lt;s:form&gt;`、`&lt;s:textfield&gt;`、`&lt;s:password&gt;`、`&lt;s:email&gt;`和`&lt;s:fielderror&gt;`标签创建一个包含用户输入验证的注册表单。 五、源码与工具 理解Struts2标签的实现原理,可以查看其...

    Struts2标签 UI标志又可以分为表单UI和非表单UI两部分

    - `&lt;s:if&gt;`、`&lt;s:elseif&gt;` 和 `&lt;s:else&gt;` 标签用于实现条件判断逻辑。 - 示例: ```xml &lt;s:if test="%{testBoolean}"&gt; &lt;p&gt;这是显示的内容&lt;/p&gt; &lt;/s:if&gt; &lt;s:elseif test="%{testBoolean == false}"&gt; &lt;p&gt;这是另...

    Struts2全部标签使用说明

    以上只是Struts2标签库的一部分,实际使用中还有更多标签如`&lt;s:textfield&gt;`(文本输入框)、`&lt;s:textarea&gt;`(文本区域)、`&lt;s:submit&gt;`(提交按钮)等,每个都有其特定的用途,极大地简化了JSP页面的编写。...

    struts2.0 标签清单

    Struts2.0是Struts框架的一个重大升级版本,它提供了更为强大且灵活的MVC架构...以上仅是Struts2.0标签库中的一部分,掌握这些标签将极大地提升开发者使用Struts2框架的能力,使Web应用程序的开发变得更加高效和优雅。

    Struts2标签库

    &lt;%@ taglib uri="/struts-tags" prefix="s" %&gt; 结合例子,重点掌握以下标签的用法 (1) &lt;s:property&gt; (2) &lt;s:set&gt; (3) &lt;s:if&gt; 、&lt;s:elseif&gt;、&lt;s:else&gt; (4) &lt;s:iterator&gt; (5) &lt;s:include&gt; (6) &lt;s:form&gt;、&lt;s:hidden&gt; (7...

    Strust2的if-else <tr></tr>用法

    以下是一个简单的示例,展示如何在Struts2中使用if-else控制`&lt;tr&gt;`标签的显示: ```jsp &lt;table&gt; &lt;s:iterator value="listOfObjects"&gt; &lt;% boolean displayRow = false; // 假设这是根据业务逻辑计算出的条件 %&gt; ...

    struts2标签库例子

    例如:&lt;s:append id="myAppendIterator"&gt; &lt;s:param value="%{myList1}" /&gt; &lt;s:param value="%{myList2}" /&gt; &lt;s:param value="%{myList3}" /&gt;&lt;/s:append&gt;&lt;s:iterator value="%{#myAppendIterator}"&gt; &lt;s:property /&gt;&lt;/...

    struts2标签解释

    `&lt;s:file&gt;`标签用于文件上传功能,与Struts2的FileUpload拦截器配合使用。 `&lt;s:form&gt;`标签创建表单,它会将表单数据提交到指定的Action。 G. `&lt;s:generator&gt;`,`&lt;s:iterator&gt;`: `&lt;s:generator&gt;`常与`s:iterator`...

    struts2增删改查,struts2分页查询

    在探讨Struts2框架下的增删改查以及...以上解析涵盖了Struts2框架中增删改查及分页查询的主要实现方式,通过JSP页面、Action类和配置文件三者的协作,我们可以高效地构建出具有动态数据展示和交互能力的Web应用程序。

    struts2标签库

    - **`&lt;s:iterator&gt;`**:用于遍历集合中的元素,类似于Struts1中的`&lt;logic:iterate&gt;`,但Struts2的实现更为高效,并且支持更复杂的操作,如排序、过滤等。 #### 结论 Struts2标签库相比于Struts1提供了更多的功能和...

Global site tag (gtag.js) - Google Analytics