414、Java框架68 -【Struts - radio标签、select标签】 2020.11.26

132 篇文章 0 订阅
11 篇文章 0 订阅

目录

0、radio标签

1、效果

2、修改 list.jsp

3、测试

4、select标签

5、效果

6、修改 list.jsp

7、测试

8、参考链接


 

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

 

8、参考链接

[01]How2j - Struts - radio标签

[02]How2j - Struts - select标签

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值