struts2传入数组(checkbox)到后台的处理方式

这是做一个简单的多选删除功能。

我看到好多人的做法是在jsp将多个选中的删除ID进行字符串拼接,然后传入后台。这样做比较麻烦。用了struts2就可以很好的解决这个问题。

下面是jsp页面的代码:

<form action="test.action" method="post">
<input type="checkbox" name="testid"/>
<input type="checkbox" name="testid"/>
<input type="checkbox" name="testid"/>
<input type="checkbox" name="testid"/>

<input type="submit" value="submit"/>
</form>

struts2中要定义一个String数组来存储选中的checkbox的ID。

下面是struts2的Action的代码:

package com.huaat.weibo.action;

/**
 * Test
 * @author  jing.yue
 * @version 2012/07/17 1.0.0
 */
@Scope("prototype")
@Component("TestAction")
public class TestAction extends BaseAction {

	private static final long serialVersionUID = 1754866855088929693L;

	//多选的Test的ID
	private String[] testid;

	/**
	 * 删除微博
	 * @return 
	 */
	public String del() {
		// TODO Auto-generated method stub
		logger.info("TestAction -- del");
		try {
			logger.info("这是选中的checkbox的大小:" + testid.length);
		} catch (Exception e) {
			e.printStackTrace();
		}
		return SUCCESS;
	}

	public void setJsonStr(String jsonStr) {
		this.jsonStr = jsonStr;
	}

	public String[] getTestid() {
		return testid;
	}

	public void setTestid(String[] testid) {
		this.testid = testid;
	}
}

struts2的配置文件在这里就不多将了。相信大家都知道。

转载于:https://my.oschina.net/castusz/blog/67667

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值