目录
0、radio标签
遍历products成为radio,并选中第二个
1、效果
访问测试地址:
http://127.0.0.1:8080/struts/listProduct
以单选框的方式遍历集合中的数据,默认选中第二个
2、修改 list.jsp
在前例checkbox标签的基础上增加s:radio标签
value表示:哪项被选中
name表示:提交到服务端用的名称
list:用于遍历的集合
listValue:显示的radio的名称
listKey:radio的value
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8" isELIgnored="false"%>
<%@ taglib prefix="s" uri="/struts-tags"%>
<%@page isELIgnored="false"%>
<s:radio name="product.id" value="2" list="products" listValue="name"
listKey="id" />
3、测试
重启tomcat,访问页面
http://127.0.0.1:8080/struts/listProduct
4、select标签
遍历products成为select标签
默认选中第2个和第3个
5、效果
访问测试地址:
http://127.0.0.1:8080/struts/listProduct
6、修改 list.jsp
使用s:select标签
name表示:提交到服务端用的名称
list:用于遍历的集合
listKey:每个option的value
listValue:显示的名称
multiple:true表示可以选中多行
size="3"表示默认显示3行
value表示:哪些被选中
注: 可以增加一个属性 theme="simple" 使得最后生成的最简单的风格的html,否则就会有一些奇奇怪怪的tr td
或者直接在struts.xml中加一句 Servlet下载文件
<constant name="struts.ui.theme" value="simple"/>
注: 如果要增加class,需要使用属性: cssClass
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8" isELIgnored="false"%>
<%@ taglib prefix="s" uri="/struts-tags"%>
<%@page isELIgnored="false"%>
<s:select label="products"
name="product.id"
list="products"
listKey="id"
listValue="name"
multiple="true"
size="3"
value="selectedProducts"
/>
7、测试
重启tomcat,访问页面
http://127.0.0.1:8080/struts/listProduct