以下为未整理的杂项,暂放于此,其中内容没有过多思考,可能会有错误
form表单使用serialize()函数
<form id="form1" action="${pageContext.request.contextPath}/ProductUpd"> <input type="hidden" name="id" id="id1"> <div class="input-group offset-1 col-10"> <div class="input-group-prepend"> <span class="input-group-text">编号</span> </div> <input type="number" class="form-control" name="product_no" id="bianhao"> <div class="input-group-prepend"> <span class="input-group-text">名称</span> </div> <input type="text" class="form-control" name="product_name" id="mingcheng"> </div> <div class="input-group offset-1 col-10"> <div class="input-group-prepend"> <span class="input-group-text">类型</span> </div> <input type="text" class="form-control" name="product_type" id="leixing"> <div class="input-group-prepend"> <span class="input-group-text">状态</span> </div> <select class="form-control" name="status" id="zhuantai"> <option value="1">有效</option> <option value="2">无效</option> </select> </div> </form>
上面表单的提交
$(function(){ $("#submit1").click(function(){ $.ajax({ url: "${pageContext.request.contextPath}/ProductUpd", type: "post", data: $("#form1").serialize(), //为了记录这个 success: function(result){ if(result==1){ alert("产品信息修改成功!"); } }, error: function(){ alert("异常!"); } }); }); });
/////////////////////////////////////////////分割线//////////////////////////////////////////////
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { int id = Integer.parseInt(request.getParameter("id")); try { ObjectMapper mapper = new ObjectMapper(); Product product = productService.selectById(id); String jsonString = mapper.writeValueAsString(product); response.setCharacterEncoding("utf-8"); response.getWriter().print(jsonString); //response.getWriter().write(jsonString); } catch (Exception e) { e.printStackTrace(); } }
上面的response.getWriter().print(jsonString)和write(jsonString)是向页面写数据,可以通过ajax的回调函数success通过参数let obj = JSON.parse(str);获取结果。append()好像也差不多,不常用,并不是分段传送,同样是一次传送。
https://www.cnblogs.com/qlqwjy/p/7455706.html上面两个方法的区别
https://blog.csdn.net/shenqueying/article/details/80841347 out和response.getWriter()的区别。
/////////////////////////////////////////////分割线//////////////////////////////////////////////
css中的position: absolute
<style type="text/css"> .father{ width: 300px; height: 300px; background-color: black; position: absolute; top:50%; left:50%; margin-top: -150px; margin-left: -150px; } .son{ /* 相对于父级元素相对后的位置进行定位,父级元素需要relative(通常)或absolute或fixed*/ width: 100px; height: 100px; background-color: pink; position: absolute; left:0; top:0; } </style> <div class="father"> <div class="son"></div> </div>
/////////////////////////////////////////////分割线//////////////////////////////////////////////
在bootstrap4中表单验证使用的is-valid和is-invalid还有图标
<!-- 添加图标,另外font-awesome使用的时候,不能只用font-awesom,需要带着所有文件 --> <style type="text/css"> /* 用font-awesome添加图标,4.3后好像就不用这样了,改成自带 */ .valid-feedback.feedback-icon, .invalid-feedback.feedback-icon { position: absolute; width: auto; bottom: 10px; right: 10px; margin-top: 0; } </style> <div class="container"> <div class="form-group position-relative"> <label for="input2">Valid with icon</label> <input type="text" class="form-control is-valid" id="input2"> <div class="valid-feedback feedback-icon"> <i class="fa fa-check"></i> </div> </div> <div class="form-group position-relative"> <label for="input3">inValid with icon</label> <input type="text" class="form-control is-invalid" id="input3"> <!-- 一个icon对应于一个父级的position-relative, 是relative在起作用不是form-control --> <div class="invalid-feedback feedback-icon"> <i class="fa fa-times"></i> </div> </div> </div>
/////////////////////////////////////////////分割线//////////////////////////////////////////////
当th表格的单元格被太多字撑开,多的字使其变成...
<tbody> <c:forEach var="product" items="${requestScope.list}"> <tr> <td style="max-width: 100px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap">${product.product_no}</td> <td>${product.product_name}</td> <td>${product.product_type}</td> <td id="${product.id}">${product.status==1?"有效":"无效"}</td> <td><button class="btn btn-primary pb-1 pt-1" onclick="shanchu(${product.id})">删除</button></td> <td><button type="button" class="btn btn-primary" onclick="xiugai(${product.id})">修改</button></td> </tr> </c:forEach> </tbody>
/////////////////////////////////////////////分割线//////////////////////////////////////////////
关于$(XX).val()的使用和conform的使用
<script type="text/javascript"> function shanchu(id){ let msg = "确定要删除本条产品信息吗?"; if (confirm(msg)){ location.href="${pageContext.request.contextPath}/del?id="+id; } } function xiugai(id){ $.ajax({ url : "${pageContext.request.contextPath}/ProductJsonId", type : "post", data : { id : id }, success : function(str) { let obj = JSON.parse(str); $("#id1").val(obj.id); $("#bianhao").val(obj.product_no); $("#mingcheng").val(obj.product_name); $("#leixing").val(obj.product_type); if(obj.status==1){ $("#zhuantai").val("1"); }else{ $("#zhuantai").val("2"); } $("#myModal").modal(); //显示模态框 } }); } </script>
/////////////////////////////////////////////分割线//////////////////////////////////////////////
bootstrap4中的justify-content-center只能对其内部的标签起作用,内部标签自适应居中,下面是自适应铺满一行,textarea中的resize: none;width: 200px;height: 100px;max-width: 200px;max-height: 100px;也可以(还没试),但右下角图标还在
<form action="${pageContext.request.contextPath}/sendtojsp" method="post" > <label for="comment">填写意见:</label> <textarea name="detail" required class="form-control" rows="3" id="comment" style="resize: none;"></textarea> <div class="btn-group d-flex"> <!--需要先定义出弹性盒子--> <input name="" type="submit" class="btn btn-outline-success flex-fill m-2" value="提交"> <input name="" type="reset" class="btn btn-outline-danger flex-fill m-2" value="重写"> </div> </form>
/////////////////////////////////////////////分割线//////////////////////////////////////////////
简单的分页显示
<ul class="pagination justify-content-center"> <c:forEach var="i" begin="1" end ="${pages.num}"> <li class="page-item"><a class="page-link" href="${省略}/result?page=${i}">第${i}页</a></li> </c:forEach> </ul>
/////////////////////////////////////////////分割线//////////////////////////////////////////////
UTF-8 Filter过滤器
public void doFilter(ServletRequest req, ServletResponse resp, FilterChain chain) throws IOException, ServletException { HttpServletRequest request = (HttpServletRequest) req; HttpServletResponse response = (HttpServletResponse) resp; String encoding = config.getInitParameter("encoding"); if (encoding != null) { response.setContentType("text/html ;charset=" + encoding); request.setCharacterEncoding(encoding); response.setCharacterEncoding(encoding); //response的设值一定要在doFilter之前,否则,当后台 //resp.getWriter().write("abc");时,这一段abc是不受utf-8的管制的, //相当于先传值后设置字符集,对于一开始传的值无效,对后边的应该有效 } chain.doFilter(request, response); }
/////////////////////////////////////////////分割线//////////////////////////////////////////////
jsp编译后的java文件的路径
C:\Users\XHQ\eclipse-workspace\.metadata\.plugins\org.eclipse.wst.server.core\tmp0\work\Catalina\localhost\项目名\org\apache\jsp
在文件中可以知道,为什么javaBean或者el表达式不能访问在<%%>中声明的变量,而可以访问到<%! %>中的变量,因为后者设置的值处于page范围,javaBean和EL表达式中访问的变量,起码在page范围以上,而page范围对应于this,也就是说,javaBean和el可以访问到保存于service外的成员变量,而不可以访问到service内的局部变量。其中session和request,application虽然在service内定义,但其值来源于pageContext,而pageContext的来源是成员变量。javaBean(应该在成员变量级定义吧)和el表达式的定义也是在成员变量级。所以访问不到service内的局部变量。
/////////////////////////////////////////////分割线//////////////////////////////////////////////
HTML中转义字符:A对应A, 对应空格, &对应&。另外,在xml文件中不能使用&,需要用&来代替,如下。。。暂时找不到了,是在jdbc的连接时?useUnicode=true&characterEncoding=UTF-8&serverTimezone=UTC&useSSL=false时使用,这里utf8和utf-8似乎一样
/////////////////////////////////////////////分割线//////////////////////////////////////////////
bootstrap4上下左右居中?左右居中可以做到,因为始终有边界,可以自适应获得不需要100vw,但是上下可以一直翻,不知道有多高,要想上下也能居中就需要设定父类组件的大小
<div class="row align-content-center justify-content-center" style="height:100vh">
align-content-center让内部元素上下居中,height: 100vh设置了上下高度。如果还有其他内容,则往下翻会翻到,就是说其实100vh也是一个值,占完了整个浏览器窗口的高度,但大小会随着浏览器窗口的大小而改变。vh是什么?
https://blog.csdn.net/weixin_42192534/article/details/80289782
/////////////////////////////////////////////分割线//////////////////////////////////////////////
关于bootstrap4布局的方式个人的认知,行->列->行,或者列->行,下面的演示
<div class="container"> <h1 align="center">XX</h1> <div class="row"> <!--行--> <div class="col-10" style="border: 1px solid #000"> <!--列--> <form> <div class="form-row"> <!--内部在分行--> <div class="col-6"> <input type="text" class="form-control"> </div> <div class="col-6"> <input type="text" class="form-control"> </div> </div> <div class="form-row mt-3"> <div class="col-6"> <input type="text" class="form-control"> </div> <div class="col-6"> <input type="text" class="form-control"> </div> </div> </form> </div>
<!--列,这里上面的列一共占据两行,使得最外层的行变粗,变成了两行,这里col-2自然也占据一个变粗后的行的两列--> <div class="col-2 d-flex justify-content-center flex-wrap align-content-center" style="border: 1px solid #f00"> <button id="sub" type="button" class="btn btn-outline-success"> 预 定 </button> </div> </div> </div>
上面还有一点要注意的是,加与不加flex-warp的效果如下
总体的展示就是是否上下占满
/////////////////////////////////////////////分割线//////////////////////////////////////////////
背景图片占满屏幕
body{ background:#fff url("images/login.jpg") no-repeat left top; background-size:cover; }
/////////////////////////////////////////////分割线//////////////////////////////////////////////
完全透明,不太可能用到
style="background:transparent;border: 0;
/////////////////////////////////////////////分割线//////////////////////////////////////////////
jquery.validate.js的简单使用
<script type="text/javascript"> $.validator.setDefaults( { submitHandler: function (form) { alert( "submitted!" ); form.submit(); } } ); $(function(){ $("#form").validate({ rules: { reachDate: { //对应的是表单元素的name属性的值,即name="reacheDate" required: true }, leaveDate: { required: true }, roomRateId: { required: true }, roomCount: { required: true } }, messages: { reachDate: "请选择入住日期", leaveDate: "请选择离开日期", roomRateId: "请选择房间类型", roomCount: "请选择房间数目" }, errorElement: "em", errorPlacement: function ( error, element ) { // Add the `invalid-feedback` class to the error element error.addClass( "invalid-feedback" ); if ( element.prop( "type" ) === "checkbox" ) { error.insertAfter( element.next( "label" ) ); } else { error.insertAfter( element ); }
//error为校验失败创建的信息提示标签,element为当前被校验的控件 }, highlight: function ( element, errorClass, validClass ) { $( element ).addClass( "is-invalid rounded-right" ).removeClass( "is-valid" );
//rounded-right,让右边的框角变成圆的,看情况加 }, unhighlight: function (element, errorClass, validClass) { $( element ).addClass( "is-valid" ).removeClass( "is-invalid" ); } }); }); $(function(){ $("#sub").click(function(){ $("#form").submit(); }); }); </script>
/////////////////////////////////////////////分割线//////////////////////////////////////////////
js传参。<a id="temp" href="javascript:void(0)" onclick="fun(this)"></a> 这里的this代表这个DOM对象,ie9后DOM对象已经被统一为js对象了,可以获得this.value对应于value属性。也可以onclick="fun(${row.ans})",这样用el表达式传值,this.val()和this.value好像不同,value是实时的,val()是预定义的,应该是。在form中onsubmit="return checkTheForm()"个人感觉这个return可以省去,因为这里的要求应该是,是表达式就行。
/////////////////////////////////////////////分割线//////////////////////////////////////////////
返回顶部
$(document).ready(function () { $("#totop").hide(); $(function () { $(window).scroll(function () { if ($(window).scrollTop() > 20) { $("#totop").fadeIn(500); } else { $("#totop").fadeOut(500); } }); $("#totop").click(function () { $('body,html').animate({ scrollTop: 0 }, 500); }); }); });
对应html
<p id="totop"> <a href="#"> <span class="glyphicon glyphicon-chevron-up"></span> </a> </p>
对应效果
p #totop { position: fixed; bottom: 18px; right: 12px; } p #totop a { text-align: center; text-decoration: none; color: #000; display: block; width: 30px; /*使用CSS3中的transition属性给跳转链接中的文字添加渐变效果*/ -moz-transition: color1s; -webkit-transition: color1s; -o-transition: color1s; } p #totop a:hover { color: #000011; } p #totop a span { background-color: #d4bbbb; z-index: -100; border: 1px solid #cccccc; border-radius: 6px; display: block; height: 30px; width: 30px; padding-top: 5px; /*使用CSS3中的transition属性给<span>标签背景颜色添加渐变效果*/ -moz-transition: background1s; -webkit-transition: background1s; -o-transition: background1s; } #totop a:hover span { background-color: #f0f0f0; }
/////////////////////////////////////////////分割线//////////////////////////////////////////////
Z-index 仅能在定位元素上奏效(例如 position:absolute;),在两个元素重叠的时候决定谁的优先级或者说高度更高,float的话就不能用,static也不能用。static是默认。位置设置为 static 的元素,它始终会处于页面流给予的位置(static 元素会忽略任何 top、bottom、left 或 right 声明)。
/////////////////////////////////////////////分割线//////////////////////////////////////////////
在js中使用EL表达式
首先el表达式是能够在js中正常使用的,但是要考虑的是js的类型。${x}如果x中是3,那么在编写后,其实可以认为没有el表达式只有翻译过后的el表达式的值。3。如果需要字符串则用"${x}"。
<!-- 假设request中type为'按钮',id为1,name为jack --> <input type="button" value="${type}" onclick="fn(${id}, '${name}')">
上面就是el表达式的使用方式。由于标签的属性是建议用引号,所以上面value=${type}也是可以的,另外,${id}是数值,在调用时为1。${name}是字符所以加上了'',如果不加就会出错,不加引号的话,传入fn这个函数的是jack,于是fun会开始寻找jack这个变量的值,但是jack并没有定义,会出现问题。但是id就不会。
el表达式在使用的时候"${}"是没有问题的,但是"${} "就会出现问题。即引号与el表达式必须挨着,其间不能由空格。
/////////////////////////////////////////////分割线//////////////////////////////////////////////
SQL中select * 虽然方便但是效率低,不用最好。set names gbk;临时修改了数据库的字符集,也可以utf8,下次连接就会失效,在这次修改中可以创建表带中文,插入数据带中文,查找数据带中文等等。
/////////////////////////////////////////////分割线//////////////////////////////////////////////
JDBC中在数据库查询的时候取别名是很有效果的,可以解决利用反射数据库中字段名与pojo属性名不同的问题,还可以解决重名问题。还有就是可以建视图来解决此类问题。
/////////////////////////////////////////////分割线//////////////////////////////////////////////
java中的路径问题
加上/则是相对于项目名的上级开始匹配。在jsp中像这样写:/项目名/地址。如果不加则是相对于项目名开始的。在jsp中这样写:地址。这一种省略了:/项目名/。在xml中classpath:是从 src/ 下开始的匹配。
/////////////////////////////////////////////分割线//////////////////////////////////////////////
XML文件第一行不能是无关的内同,注释都不行。
/////////////////////////////////////////////分割线//////////////////////////////////////////////
注入攻击
在一个有用户名和密码的表单中,在用户名中填写。username' or 1=1 # 就是一个注入攻击。这样的语句在sql中会变成。select ... from ... where loginname = 'username' or 1 = 1 #' and pwd = pwd。在#后的会被注释。
/////////////////////////////////////////////分割线//////////////////////////////////////////////
(function(){ })(),这是匿名函数的自调用。
/////////////////////////////////////////////分割线//////////////////////////////////////////////
EL表达式获取pojo类属性的时候用的getXxx(),没有这个方法就会出现找不到属性的异常。我甚至认为没有属性都可以但是不能没有方法(后面这句话没试)。
/////////////////////////////////////////////分割线//////////////////////////////////////////////
js中this的小范围总结
首先有两点关于js。其一、this本来就是用来访问对象的,其二、js中的作用域只有函数作用域和全局作用域。当在函数中使用this时,很明显这是要访问对象的,但我认为js中的对象也可以分为两种,全局对象和普通对象。也就是说这里的全局对象和第二条的全局作用域是一个,都是window AO。在作用域链中有局部作用域和全局作用域,但是全局作用域是全局对象。所以在通过作用域链访问时(即不通过this),访问不到普通对象的属性。只能访问到全局对象的属性,或者说是全局变量。还有就是函数中的局部变量由自定义变量和传递进来的参数所组成。还有就是对象中的函数也是类似于函数属性的存在,所以在一个对象中的函数,调用该对象中的另一个函数也是需要this的。
/////////////////////////////////////////////分割线//////////////////////////////////////////////
表达式:感觉表达式就是等号右边的东西,但是java和js中对于已经声明的变量x,x=1的返回值为1,所以也可以认为是表达式吧。
/////////////////////////////////////////////分割线//////////////////////////////////////////////
没见过的写法
String msg = "hello";
response.getWriter().print("<script>alert('"+msg+"');location.href='productController';</script>");
/////////////////////////////////////////////分割线//////////////////////////////////////////////
ssm中配置dao的实现类时,<property name="basePackage" value="...dao"/>,这里要配置到dao,如果配置到接口的上一层,即不到dao,则不能识别。
/////////////////////////////////////////////分割线//////////////////////////////////////////////
在js中"6"-1==5,"6"+"1"=="61",null+5==5
/////////////////////////////////////////////分割线//////////////////////////////////////////////
(4>4)?9.9:9; syso输出的结果为9.0
/////////////////////////////////////////////分割线//////////////////////////////////////////////
目前所知的Vue中只有filter中是全局作用域
/////////////////////////////////////////////分割线//////////////////////////////////////////////
三个选项的EL表达式
${status == 0 ? "未审批" : (status == 1 ? "审批通过" : "审批驳回")}
/////////////////////////////////////////////分割线//////////////////////////////////////////////
public class asdf { public asdf(String str1, String str2) { System.out.println("str"); } public asdf(String str) { this(str, null); //正确,优先匹配子类?,null比较特殊 //如果把下面的构造改成Integer则不行, //改成Integer后,这一行会报靠上的一个构造函数的错误 //例如这里报String String ambiguous,当然如果类型相同则直接找类型相同的 } public asdf(String str1, Object str2) { System.out.println("obj"); } public static void main(String[] args) { new asdf(null); } }
/////////////////////////////////////////////分割线//////////////////////////////////////////////
public class asdf { public asdf(String str1, Test str2) { System.out.println("str"); } public asdf(String str) { this(str, null); } public asdf(String str1, Test2 str2) { System.out.println("obj"); } public static void main(String[] args) { Test test = new Test2(); new asdf("123", test); //输出str,说明,函数中参数传递时,依靠引用(指针)的类型 //但getClass()获取的是实际堆中对象的类型 System.out.println(test.getClass()); System.out.println(test instanceof Test2); } } class Test{ public Test() { } } class Test2 extends Test{ public Test2() { } }
/////////////////////////////////////////////分割线//////////////////////////////////////////////
接口中的属性的默认是public static final (只能是 public static final)、方法是public abstract(只能是 public abstract)(总忘)
/////////////////////////////////////////////分割线//////////////////////////////////////////////
class Test{ public void print() { System.out.println("可以调用"); } } //下面是main方法中 ((Test)null).print(); 上面的内容不会报错,但是运行时会报空指针异常java.lang.NullPointerException
/////////////////////////////////////////////分割线//////////////////////////////////////////////
<form class="form-inline justify-content-center"> <div class="form-group mr-2"> <label for="exampleInputName2">Id:</label> <input type="text" class="form-control" name="id" id="exampleInputName2"> </div> <div class="form-group mr-2"> <label for="exampleInputEmail2">Name:</label> <input type="text" class="form-control" name="name" id="exampleInputEmail2"> </div> <button type="button" class="btn btn-primary" @click="getAllList">搜索</button> </form>
上面标签对应的Vue事件是
getAllList(){ this.$http.get("Vue").then(result=>{ alert("zhixingle"); alert(result.url); this.list = result.body; alert(result.body); }) }
当最下面的button标签的type是submit时,无论你怎样提交但list列表却一直不变,主要的原因就是。当点击提交后,getAllList()方法其实已经获取到了数据,并且已经更新了list属性,但是由于button处于form标签中,并且type时submit,这时候表单也会发起一次请求,但是form表单中没有action属性,相当于action属性值未"",这时会刷新页面重新加载。所以感觉没有给list赋值,其实已经赋值过了。这也说明form表单有页面跳转的作用。
/////////////////////////////////////////////分割线//////////////////////////////////////////////