表格的增删改查

1.查询数据

     

2.增加数据

3.修改数据

4.删除数据

1.一行删除

2.批量删除

function delAllArticles(id) {
		var ids = "";

		var idchks = document.getElementsByName("id");

		for (var i = 0; i < idchks.length; i++) {
			if (idchks[i].checked) {
				var id = idchks[i].value;
				ids += "id=" + id + "&";
			}
		}
		if (ids == "") {
			alert("请选择要删除的记录!");
			return;
		}
		if (confirm("确定要删除吗?"))
			location = "servlet/DelectServlet?" + ids;
	}

	function selAll(a) {
		var sel = a.checked;
		var ids = document.getElementsByName("id");
		for (var i = 0; i < ids.length; i++) {
			ids[i].checked = sel;
		}
	}
	
       String[] ids = request.getParameterValues("id");
		
		StringBuffer b = new StringBuffer();
		for(int i = 0  ; i < ids.length ; i++){
			b.append(ids[i] );
			if(i < ids.length - 1)
				b.append(",");
		}
		
		//"1,3"
		String sql = "delete from t_article where id in (" + b.toString() + ")";
       

主要说一下带参数的路径

<a href="servlet/UpdateInputServlet?id=${a.id}" title="点击编辑文章">编辑</a>

获得该行的id参数

之后在servlet/UpdateInputServlet路径下调用时用

int id = Integer.parseInt(request.getParameter("id"));

展开阅读全文

没有更多推荐了,返回首页