struts2 如何获取jsp中radio的值

本文介绍了一组具有相同名称属性的Radio按钮如何在Java后端获取选中项的值,并展示了具体的HTML实现及对应的Java DTO对象。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

多个radio只要名字name相同,那么他们就是一组 
然后在你的Action中,private String xxxx; 
xxxx是与你的一组radio的name相同,那么你选择哪一个 

String xxxx里面的值就是被选中的那个radio的value值

XXX.jsp

<table id="RadioButtonList1" border="0">
							<tr>
								<td>
									<input id="RadioButtonList1_0" type="radio"
										name="RadioButtonList" value="办公室人员" checked="checked"
										tabindex="3" />
									<label for="RadioButtonList1_0">
										办公室
									</label>
								</td>
								<td>
									<input id="RadioButtonList1_1" type="radio"
										name="RadioButtonList" value="仓库管理员" tabindex="3" />
									<label for="RadioButtonList1_1">
										仓管
									</label>
								</td>
								<td>
									<input id="RadioButtonList1_2" type="radio"
										name="RadioButtonList" value="客户" tabindex="3" />
									<label for="RadioButtonList1_2">
										客户
									</label>
								</td>
								<td>
									<input id="RadioButtonList1_3" type="radio"
										name="RadioButtonList" value="访客" tabindex="3" />
									<label for="RadioButtonList1_3">
										访客
									</label>
								</td>
							</tr>
						</table>


package cargo.web.dto;
public class UserDto {
	/*
	 * 数据传输对象,用于与用户有关的功能,如登录
	 * @author johnny
	 * time 2011-12-28
	 */
	private String name;
	private String password;
	private String RadioButtonList ;
	
	public UserDto() {
		
	}
	//-------------------------getter&&setter---------------------


package cargo.web.controller;

UserAction

public String login()throws Exception{
		System.out.println("-----------user login ing-------------");
		String name=userDto.getName();
		String password = userDto.getPassword();
		String radioButtonList = userDto.getRadioButtonList();
		System.out.println("RadioButtonList-----"+radioButtonList);


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值