1、跳转页面
location.herf="url";
2、先遍历checkbox,再通过checked获取同行的id,先选取,再删除的算法思路
用for循环来遍历:
var ids="";
for(var i=1;i<$("input[type='checkbox']").length;i++)
{
if($("input[type='checkbox']:eq(i)").prop("checked"))
{
ids+=$("input[type='checkbox']:eq(i)").parent().parent().children().eq(0).children().eq(0).prop("id");
if(i!=$("input[type='checkbox']").length-1)
{
ids+=",";
}
}
}
用.each()来遍历:
var ids="";
var i=0;
$("input[type='checkbox']").each(function(index,element){
if(index>0)
{
if($(this).prop("checked"))
{
var id=$(this).parent().parent().children().eq(0).children().eq(0).val();
ids+=id;
i++;
if(!$(this).is(":last"))
{
ids+=",";
}
}
}
});
JQuery中的特殊选择器--this:
https://blog.csdn.net/LHJBK/article/details/51541235jQuery length和size()区别总结如下:
1.length是属性,size()是方法。
2.如果你只是想获取元素的个数,两者效果一样既 $("img").length 和 $("img").size() 获取的值是一样的;但是如果是获取字符串的长度就只得用length, 如 $("#text").val().length 看看官网的解释(http://api.jquery.com/size/):
The .size()
method is deprecated as of jQuery 1.8. Use the .length
property instead.
The .size()
method is functionally equivalent to the .length
property; however, the .length
property is preferred because it does not have the overhead of a function call
jQuery length和size()区别 从上可以看出size()是调用length属性实现的,而且在jquery 1.8后 length取代了 size() ,因为length不需要返回一个函数调用,更优秀。
3、选择检查框的处理逻辑(全选和全不选)
if($("input[type='checkbox']:first").checked)
{
$("input[type='checkbox:not(:first)").prop($("[input type='checkbox']:first").prop());
}
4、在Servlet中输出页面的东西
PrintWriter out=response.getWriter();
out.println();
5、PreparedStatement 的 execute方法和executeUpdate方法区别
方法executeUpdate
用于执行 INSERT、UPDATE 或 DELETE 语句以及 SQL DDL(数据定义语言)语句,例如 CREATE TABLE 和 DROP TABLE。INSERT、UPDATE 或 DELETE 语句的效果是修改表中零行或多行中的一列或多列。executeUpdate 的返回值是一个整数(int),指示受影响的行数(即更新计数)。对于 CREATE TABLE 或 DROP TABLE 等不操作行的语句,executeUpdate 的返回值总为零。
方法execute
可用于执行任何SQL语句,返回一个boolean值,表明执行该SQL语句是否返回了ResultSet。如果执行后第一个结果是ResultSet,则返回true,否则返回false。但它执行SQL语句时比较麻烦,通常我们没有必要使用execute方法来执行SQL语句,而是使用executeQuery或executeUpdate更适合,但如果在不清楚SQL语句的类型时则只能使用execute方法来执行该SQL语句了
显然方法execute多了判断是否有结果集返回
6、
7、jquery书写问题
错误的页面加载后点击无反应:
$("#selectit").click(function(){
$(":checkbox[name='selectit']").each(function(index, element) {
$(this).prop("checked",$("#selectit").prop("checked"));
});
});
改正后的正常:
$(function(){
$("#selectit").click(function(){
$(":checkbox[name='selectit']").each(function(index, element) {
$(this).prop("checked",$("#selectit").prop("checked"));
});
});
});
关于加上$(function());的重要性
8、在读取resultset内容时犯的错误
处理结果集时不小心犯的错:Before start of result set
解决方法:while(rs.next())
当时考虑只取一条数据,所以把while(rs.next())给取消了,结果报错!
9、在修改页面想传递参数到修改的servelet,然后存到数据库,结果在js里试了好久;后来才发现,form就自带传参数的功能!!!
10、在Servelet中跳转页面用啥??
response.sendRedirect("bookList.jsp");
在jsp中跳转页面用啥??
location.href="modifyBook.jsp?id="+id;
11、Servelet返回参数传递
PrintWriter out=response.getWriter();
out.println("success");
12、正则表达式的用法:
var reg=/^[+]{0,1}(\d+)$/;
if($.trim($("input[name='id']").val()).length==0)
{
$("input[name='id']").focus();
$("input[name='id']").select();
alert("请输入ID!")
return false;
}else if(!(reg.test($("input[name='id']").val())))
{
$("input[name='id']").focus();
$("input[name='id']").select();
alert("ID应为正整数!")
return false;
}
13、获取checkbox的值:.prop("checked");
checkboxObject.checked=true|false
14、confirm()加变量显示,alert()可以吗?
var s=confirm("确定要删除这"+i+"条信息吗?");
15、
UPDATE table_name
SET column1=value1,column2=value2,...
WHERE some_column=some_value;
16、增强for循环
for(String s:ids)
{
System.out.println("跳转成功3");
id=Integer.parseInt(s);
dao.deleteBook(id);
}
17、
18、比较字符串
19、在DeleteIt的Servelet执行完后,用下面这个跳转方法来更新主页的内容,结果失败了,没有反应
response.sendRedirect("bookList.jsp");
后来用了这个方法:
PrintWriter out=response.getWriter();
out.println("true");
$.post("DeleteIt",{ids:ids},function(data){
if(data){
window.location.reload();
}
之所以回传用true,是因为回传success,用if(a.equals(b))的方法也是不行,可能是因为这个方法只是在Java中用的,在jquery中不行吧?
20、mysql的驱动程序,将其拷贝到web-inf/lib下
21、severlet中是不能直接使用jsp的九大内置对象的,它只接受了request和response两个参数,所以这两个可以直接用的。