模块八.jsp九大内置对象(重要的)
<%@page import="java.util.Calendar"%> <%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%> <!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <style type="text/css"> *{ font-size: 30px; font-weight: bold; } h4{ color: red; } </style> <title>Insert title here</title> </head> <body> <h1>九大内置对象的写法</h1> <% //out.write("aaaaa"); pageContext.getOut().write("这是由pageContext管理的对象哦"); //request pageContext.getRequest(); //response pageContext.getResponse(); //session pageContext.getSession(); //exception pageContext.getException(); //page pageContext.getPage(); //config pageContext.getServletConfig(); //application pageContext.getServletContext(); %> <hr> <h4>pageContext是可以存储数据,但是其作用域只能供其本身的jsp页面使用</h4> <!-- 对象一pageContext --> <% pageContext.setAttribute("aaa", "我是pageContext的存放范围最小的数据"); pageContext.setAttribute("aa", "1001"); String info=(String)pageContext.getAttribute("aaa"); String inf=(String)pageContext.getAttribute("aa"); out.write("<br>"); out.write(info); out.write(inf); %> <!-- 对象二 request --> <h4>request对象中的数据是可以形成多个页面共享数据,但是要通过请求转发的 方式打开其他页面才能形成共享数据</h4> <% request.setAttribute("b", "我是request的数据"); //pageContext.setAttribute("bbb", "我是request的数据存放的范围是第二小的数据", PageContext.REQUEST_SCOPE); String infob=(String)request.getAttribute("b"); out.write("<br>"); out.write(infob); //request.getRequestDispatcher("BB.jsp").forward(request, response); %> <br> <h4>说明session对象能不能共享数据和浏览器有关</h4> <!-- 对象三 Session--> <% session.setAttribute("ccc", "我是session的数据存放的范围是第二大的数据"); session.setAttribute("cc", "我是session的数据存放的范围是第二大的数据1003@@@"); String c=(String)session.getAttribute("ccc"); String cc=(String)session.getAttribute("cc"); out.write(c); out.write(cc); %> <h4>这是application对象的数据与服务器有关,只要服务器不停止,数据都能共享</h4> <!-- 对象四 范围最大 --> <% pageContext.setAttribute("ddd", "我是application的数据存放的范围是第一大的数据",PageContext.APPLICATION_SCOPE); String d=(String)application.getAttribute("ddd"); application.setAttribute("dd", "我是application创建的第二个数据类型是one.two"); String dd=(String)application.getAttribute("dd"); out.write("<br>"); out.write(d); pageContext.getOut().write(dd); application.setAttribute("e", "我是application创建的第三个数据类型是one.tree"); String e=(String)application.getAttribute("e"); pageContext.getOut().write(e); application.setAttribute("f", "我是application创建的第三个数据类型是one.four"); String f=(String)application.getAttribute("f"); pageContext.getOut().write(f); %> <!-- //out.write("aaaaa"); pageContext.getOut().write("这是由pageContext管理的对象哦"); --> <h1>--------------------对象五的获取 pageContext.getOut()</h1> <% //创建日历类 Calendar calendar =Calendar.getInstance(); int AM_PM=calendar.get(calendar.AM_PM); if(AM_PM==calendar.AM){ pageContext.getOut().write("<h1 style=' color:red'>获取上午时间</h1>"); }else if(AM_PM==calendar.PM){ pageContext.getOut().write("<h1 style=' color:green'>获取下午时间</h1>"); } %> <h1>-------------page-------------对象六 </h1> <% pageContext.getOut().write((page.equals(this)?"page是当前对象":"page不是当前对象")); %> con <h1>--------------------------对象7 ----Confign </h1> <% String name = config.getServletName(); out.write(name); %> </body> </html>
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%> <!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <style type="text/css"> *{ font-size: 30px; font-weight: bold; } h1{ color: red; } </style> <title>Insert title here</title> </head> <body> <h1>--------------------对象二 request的获取</h1> <% //方法一 request对象自己直接获得数据 String b=(String)request.getAttribute("b"); //方法二 pageContext帮request获得数据 //String b=(String)pageContext.getAttribute("b", PageContext.REQUEST_SCOPE); out.write("我获得了AA.jsp页面的request对象的数据:"+b); %> <h1>--------------------对象一不能获取成功</h1> <% /* String info=(String)pageContext.getAttribute("aaa"); out.write(info); */ %> <hr> <h1>--------------------对象三的获取</h1> <% //方法一 使用session直接获得数据 String c=(String)session.getAttribute("ccc"); //方法二 pageContext帮session获得数据 String cc=(String)pageContext.getAttribute("cc", PageContext.SESSION_SCOPE); out.write("我获得了AA.jsp页面的session对象的数据:"+c); out.write("我获得了AA.jsp页面的session对象的数据:"+cc); %> <hr> <h1>--------------------对象四的获取</h1> <% //方法一 //String ddd=(String)application.getAttribute("ddd"); String ddd=(String)pageContext.getAttribute("ddd",PageContext.APPLICATION_SCOPE); out.write("我获得了AA.jsp页面的application对象的数据:"+ddd); String e=(String)application.getAttribute("e"); pageContext.getOut().write(e+"这是对象e"); %> <hr> <h1> </body> </html>
模块九jsp:四大作用域
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%> <!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title>数据类</title> <style type="text/css"> *{ color: red; } </style> </head> <body> <h1>方案四:利用二个JSP动作将数据存储起来</h1> <!--完全使用jsp动作将数据放入四大域 存储起来 --> <!-- 创建javaBean类的对象 --> <jsp:useBean id="people" class="com.People.People" scope="application"></jsp:useBean> <jsp:setProperty property="id" name="people" value="1001"/> <jsp:setProperty property="name" name="people" value="小红一号"/> <jsp:setProperty property="age" name="people" value="23"/> <jsp:setProperty property="sex" name="people" value="男"/> <jsp:setProperty property="phone" name="people" value="123456678"/> <jsp:setProperty property="addr" name="people" value="江西南昌"/> <jsp:setProperty property="height" name="people" value="189cm"/> <jsp:setProperty property="weight" name="people" value="64kg"/> <jsp:setProperty property="phone" name="people" value="123456678"/> <jsp:setProperty property="a" name="people" value="a属性是人皮肤的色彩pink"/> <jsp:setProperty property="b" name="people" value="b属性是人穿衣服的color"/> <jsp:setProperty property="c" name="people" value="b属性是人类未知的属性"/> <hr> <h2>创建第二个人</h2> <jsp:useBean id="people2" class="com.People.People" scope="application"></jsp:useBean> <jsp:setProperty property="id" name="people2" value="1002"/> <jsp:setProperty property="name" name="people2" value="小明二号"/> <jsp:setProperty property="age" name="people2" value="23"/> <jsp:setProperty property="sex" name="people2" value="男"/> <jsp:setProperty property="phone" name="people2" value="123456678"/> <jsp:setProperty property="addr" name="people2" value="江西南昌"/> <jsp:setProperty property="height" name="people2" value="189cm"/> <jsp:setProperty property="weight" name="people2" value="64kg"/> <jsp:setProperty property="phone" name="people2" value="123456678"/> <jsp:setProperty property="a" name="people2" value="a属性是人皮肤的色彩green"/> <jsp:setProperty property="b" name="people2" value="b属性是人穿衣服的color"/> <jsp:setProperty property="c" name="people2" value="b属性是人类未知的属性"/> <h2>创建第三个人</h2> <jsp:useBean id="people3" class="com.People.People" scope="application"></jsp:useBean> <jsp:setProperty property="id" name="people3" value="1003"/> <jsp:setProperty property="name" name="people3" value="小户三号"/> <jsp:setProperty property="age" name="people3" value="23"/> <jsp:setProperty property="sex" name="people3" value="男"/> <jsp:setProperty property="phone" name="people3" value="123456678"/> <jsp:setProperty property="addr" name="people3" value="江西南昌"/> <jsp:setProperty property="height" name="people3" value="189cm"/> <jsp:setProperty property="weight" name="people3" value="64kg"/> <jsp:setProperty property="phone" name="people3" value="123456678"/> <jsp:setProperty property="a" name="people3" value="a属性是人皮肤的色彩red"/> <jsp:setProperty property="b" name="people3" value="b属性是人穿衣服的color"/> <jsp:setProperty property="c" name="people3" value="b属性是人类未知的属性"/> <h2>创建第四个人</h2> <jsp:useBean id="people31" class="com.People.People" scope="application"></jsp:useBean> <jsp:setProperty property="id" name="people31" value="1004"/> <jsp:setProperty property="name" name="people31" value="小户三号"/> <jsp:setProperty property="age" name="people31" value="23"/> <jsp:setProperty property="sex" name="people31" value="男"/> <jsp:setProperty property="phone" name="people31" value="123456678"/> <jsp:setProperty property="addr" name="people31" value="江西南昌"/> <jsp:setProperty property="height" name="people31" value="189cm"/> <jsp:setProperty property="weight" name="people31" value="64kg"/> <jsp:setProperty property="phone" name="people31" value="123456678"/> <jsp:setProperty property="a" name="people31" value="a属性是人皮肤的色彩red"/> <jsp:setProperty property="b" name="people31" value="b属性是人穿衣服的color"/> <jsp:setProperty property="c" name="people31" value="b属性是人类未知的属性"/> </body> </html>
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%> <!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title>Insert title here</title> <style type=""> *{ color: red; font-size: 30px; font-weight: bold; } </style> </head> <body> <h1> 取出数据内容</h1> <jsp:useBean id="people" class="com.People.People" scope="application"></jsp:useBean> <P>出生编号:<jsp:getProperty property="id" name="people"/></P> <P>姓名:<jsp:getProperty property="name" name="people"/></P> <P>年龄:<jsp:getProperty property="age" name="people"/></P> <P>性别:<jsp:getProperty property="sex" name="people"/></P> <P>手机号:<jsp:getProperty property="phone" name="people"/></P> <P>家庭地址:<jsp:getProperty property="addr" name="people"/></P> <P>身高:<jsp:getProperty property="height" name="people"/></P> <P>体重:<jsp:getProperty property="weight" name="people"/></P> <P>属性a:<jsp:getProperty property="a" name="people"/></P> <P>属性b:<jsp:getProperty property="b" name="people"/></P> <P>属性c:<jsp:getProperty property="c" name="people"/></P> <hr> <jsp:useBean id="people2" class="com.People.People" scope="application"></jsp:useBean> <P>出生编号:<jsp:getProperty property="id" name="people2"/></P> <P>姓名:<jsp:getProperty property="name" name="people2"/></P> <P>年龄:<jsp:getProperty property="age" name="people2"/></P> <P>性别:<jsp:getProperty property="sex" name="people2"/></P> <P>手机号:<jsp:getProperty property="phone" name="people2"/></P> <P>家庭地址:<jsp:getProperty property="addr" name="people2"/></P> <P>身高:<jsp:getProperty property="height" name="people2"/></P> <P>体重:<jsp:getProperty property="weight" name="people2"/></P> <P>属性a:<jsp:getProperty property="a" name="people2"/></P> <P>属性b:<jsp:getProperty property="b" name="people2"/></P> <P>属性c:<jsp:getProperty property="c" name="people2"/></P> <hr> <jsp:useBean id="people3" class="com.People.People" scope="application"></jsp:useBean> <P>出生编号:<jsp:getProperty property="id" name="people3"/></P> <P>姓名:<jsp:getProperty property="name" name="people3"/></P> <P>年龄:<jsp:getProperty property="age" name="people3"/></P> <P>性别:<jsp:getProperty property="sex" name="people3"/></P> <P>手机号:<jsp:getProperty property="phone" name="people3"/></P> <P>家庭地址:<jsp:getProperty property="addr" name="people3"/></P> <P>身高:<jsp:getProperty property="height" name="people3"/></P> <P>体重:<jsp:getProperty property="weight" name="people3"/></P> <P>属性a:<jsp:getProperty property="a" name="people3"/></P> <P>属性b:<jsp:getProperty property="b" name="people3"/></P> <P>属性c:<jsp:getProperty property="c" name="people3"/></P> <jsp:useBean id="people31" class="com.People.People" scope="application"></jsp:useBean> <P>出生编号:<jsp:getProperty property="id" name="people31"/></P> <P>姓名:<jsp:getProperty property="name" name="people31"/></P> <P>年龄:<jsp:getProperty property="age" name="people31"/></P> <P>性别:<jsp:getProperty property="sex" name="people31"/></P> <P>手机号:<jsp:getProperty property="phone" name="people31"/></P> <P>家庭地址:<jsp:getProperty property="addr" name="people31"/></P> <P>身高:<jsp:getProperty property="height" name="people31"/></P> <P>体重:<jsp:getProperty property="weight" name="people31"/></P> <P>属性a:<jsp:getProperty property="a" name="people31"/></P> <P>属性b:<jsp:getProperty property="b" name="people31"/></P> <P>属性c:<jsp:getProperty property="c" name="people31"/></P> </body> </html>
模块十EL表达式
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%> <!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <style type="text/css"> *{ color: black; font-size: 45px; } </style> <title>Insert title here</title> </head> <body> <!-- 算数运算 --> ${4+6 } ${4/6 } ${4*6 } <br> ${3222*89 } <br> ${23 mod 5 }<br> ${23/5 }<br> <% request.setAttribute("age", 56); %> ${age-5 }<br> <br> <!-- 关系运算符 --> ${age/11>7 }<br> ${age/11<=7 }<br> ${age/11>=7 }<br> ${age/11<7 }<br> ${age/11==7 }<br> <!-- 逻辑运算符 --> ${ age mod 3==0 && age/5 ge 2}<br> ${ age mod 3 ==0|| age/5 ge 2}<br> <%-- 空运算符--%> <% int [] nums =null; pageContext.setAttribute("n", nums); %> ${empty(n) }<br> <!-- 三元运算符 --> ${age/2+3-6>45?"AAA":"BBB" }<br> <!--练习题 --> <h2> ${23+67*90 }<br> ${3>2?3:2 }<br> </h2> </body> </html>
<%@page import="java.util.HashMap"%> <%@page import="java.util.Map"%> <%@page import="java.util.ArrayList"%> <%@page import="java.util.List"%> <%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%> <!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title>Insert title here</title> <style type="text/css"> *{ font-size: 34px; } </style> </head> <body> <% Map<String,String>map =new HashMap<>(); map.put("book1","JAVA程序设计"); map.put("book2","JAVA程序设计1"); map.put("book3","JAVA程序设计2"); map.put("book4","JAVA程序设计3"); map.put("book5","JAVA程序设计4"); request.setAttribute("bo", map); Map<String,String>map1 =new HashMap<>(); map1.put("boy1","AAAA"); map1.put("boy2","BB"); map1.put("boy3","CC"); map1.put("boy4","DD"); request.setAttribute("boy", map1); List<Map<String,String>>oList =new ArrayList<>(); oList.add(map); oList.add(map1); pageContext.setAttribute("ot", oList); %> <!-- MAP集合查找 --> ${bo.book1}<br> ${bo.book2}<br> ${bo.book3}<br> ${bo.book4}<br> ${bo.book5}<br> <h1 style="color: red;">===============</h1> ${boy.boy1}<br> ${boy.boy2}<br> ${boy.boy3}<br> ${boy.boy4}<br> <h1 style="color: green;">===============</h1> ${ot[0].book3} ,<br> <%-- ${0t[1]["boy2"] } --%> <!-- 集合中 --> ${ot[1].boy1}<br> ${ot[1].boy2}<br> ${ot[1].boy3}<br> </body> </html>
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%> <!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title>Insert title here</title> <style type="text/css"> *{ font-size:30px; font-weight: bold; background:pink; } h1{ background-color: green; color: black; font-weight: bold; } h2{ color: black; border: 2px solid; background-color: yellow; } h3{ color: pink; background-color: red; } </style> </head> <body> <h1> ## seesion 浏览器不切 ## application 服务器不关闭 ## request:请求转发跳转页面的情况,只能两个页面共享数据 ## pageContext:该对象中只能页面自己用 ## 才能用setAttribute的方法 ## 将四作用域排序** ## **pageContext request seesionn application** </h1> <!-- JSP 中的四大域 存放数据称为四大域 按照作用域从小到大 1 pageContext:页面本身使用,其他页面并不能共享数据。 2 resquest; 只能在请求转发的情况下共享数据 3 Session 在不切浏览器的情况下 4 application 在不关闭浏览器的前提下,任何都能共享数据。 --> <h1>===========这个是什么?=====${pageScope.a } ${sessionScope.a }<br> ${sessionScope.a }<br> ${applicationScope.a }<br></h1> <% pageContext.setAttribute("a", "pageContext@1APPLE"); request.setAttribute("b", "request@2.BROW 123"); session.setAttribute("c", "session@3.DFER true"); application.setAttribute("d", "application@4.PINK"); %> <!-- 方式一 获取--> <%=pageContext.getAttribute("a") %><br> <%=request.getAttribute("b") %><br> <%=session.getAttribute("c") %><br> <%=application.getAttribute("d") %><br> <br><br><hr> <%=pageContext.getAttribute("a") %><br> <%=pageContext.getAttribute("b",pageContext.REQUEST_SCOPE ) %><br> <%=pageContext.getAttribute("c",pageContext.SESSION_SCOPE ) %><br> <%=pageContext.getAttribute("d",pageContext.APPLICATION_SCOPE ) %><br> <h1>====================代码实例0=========================</h1> <!-- 方式二 --> <%=pageContext.getAttribute("a") %><br> <%=pageContext.getAttribute("a",pageContext.REQUEST_SCOPE ) %><br> <%=pageContext.getAttribute("a",pageContext.SESSION_SCOPE ) %><br> <%=pageContext.getAttribute("a",pageContext.APPLICATION_SCOPE ) %><br> <br><br><hr> <!-- -方式三 快速查找 findAttribute 改方法查找数据作用域从小到大 pageContext resquest; Session application --> <h3>====================代码实例一=========================</h3> <%=pageContext.findAttribute("a") %><br> <%=pageContext.findAttribute("b") %><br> <%=pageContext.findAttribute("b") %><br> <%=pageContext.findAttribute("b") %><br> <br><br><hr> <h3>==================代码实例二===========================</h3> <%=pageContext.findAttribute("a") %><br> <%=pageContext.findAttribute("b") %><br> <%=pageContext.findAttribute("c") %><br> <%=pageContext.findAttribute("c") %><br> <br><br><hr> <h3>===================代码实例三==========================</h3> <%=pageContext.findAttribute("a") %><br> <%=pageContext.findAttribute("b") %><br> <%=pageContext.findAttribute("c") %><br> <%=pageContext.findAttribute("d") %><br> <br><br><hr> <h2>==========================方案四======================</h2> <!-- 方式四 --> <!-- EL表达式语法 --> <!-- 该表达式其内部就是 findAttribute 快速查找 请看下面代码 可以获得八大数据类型--> <!-- findAttribute === ${a }<br> --> <h2>================代码实例0=============================</h2> ${a }<br> ${a }<br> ${a}<br> ${a}<br> <h2>================代码实例1============================</h2> ${a }<br> ${b }<br> ${b}<br> ${b}<br> <h2>================代码实例2============================</h2> ${a }<br> ${b }<br> ${c}<br> ${c}<br> <h2>================代码实例3============================</h2> ${a }<br> ${b }<br> ${c}<br> ${d}<br> <h3>-------------------------------解决问题内容--------------------------------</h3> <!-- 解决上面的问题 --> <!-- EL pageContextScope --> ${pageScope.a }<br> <!-- requestScope --> ${sessionScope.a }<br> <!-- sessionScope --> ${sessionScope.a }<br> <!-- applicationScope --> ${applicationScope.a }<br> </body> </html>
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%> <!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title>Insert title here</title> <style type="text/css"> *{ font-size: 34px; } </style> </head> <body> <!-- JSP 中的四大域 存放数据称为四大域 按照作用域从小到大 1 pageContext:页面本身使用,其他页面并不能共享数据。 2 resquest; 只能在请求转发的情况下共享数据 3 Session 在不切浏览器的情况下 4 application 在不关闭浏览器的前提下,任何都能共享数据。 --> <% pageContext.setAttribute("a", "pageContext@1APPLE"); request.setAttribute("a", "request@2.BROW"); session.setAttribute("a", "session@3.DFER"); application.setAttribute("a", "application@4.PINK"); %> <!-- 方式一 获取--> <%=pageContext.getAttribute("a") %><br> <%=request.getAttribute("a") %><br> <%=session.getAttribute("a") %><br> <%=application.getAttribute("a") %><br> <br><br><hr> <!-- 方式二 --> <%=pageContext.getAttribute("a") %> <%=pageContext.getAttribute("a",pageContext.REQUEST_SCOPE ) %><br> <%=pageContext.getAttribute("a",pageContext.SESSION_SCOPE ) %><br> <%=pageContext.getAttribute("a",pageContext.APPLICATION_SCOPE ) %><br> <br><br><hr> <!-- -方式三 快速查找 findAttribute --> <%=pageContext.findAttribute("a") %><br> <%=pageContext.findAttribute("a") %><br> <%=pageContext.findAttribute("a") %><br> <%=pageContext.findAttribute("a") %><br> <br><br><hr> </body> </html>
模块十一JSTL标签库。
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%> <!-- @1使用taglib url:在线标签库的地址 @2prefix 本地的前首写字母 --> <%@taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %> <!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title>JSTL标签库的使用一通用标签库</title> <style type="text/css"> *{ color: black; font-size: 30px; font-weight: bolder; } h2{ color: white; background-color: black; } </style> </head> <body> <h2 style="align-content: center; text-align: center;">JSTL标签库的使用一通用标签库1</h2> <%request.setAttribute("a", "我是数据a定义了一个数据为HellowA") ;%> <%request.setAttribute("b", "我是数据b定义了一个数据为HellowB") ;%> <!-- El表达式 --> <h2>用El表达式获取的数据</h2> <h1>${a }</h1><br> <h1>${b }</h1><br> <h3>通用标签set使用</h3> <!-- <!-- var:对应数据名称 value:数据的值 scope:四大域的名称 page:pageContext resquest: resquest session:session application: application --> <%-- <c:set var="a1" value="hellow1" scope="resquest"></c:set> 标签库${a1 } <c:set var="b1" value="hellow1" ></c:set> --%> <%-- ${pageScrope.a } --%> <h2>表达式标签库</h2> <h2> 1 scope="四大作用域"。 2 var="对应的变量名" 。 3 value"对应的值" 。 @1用表达式$(a1)获取。 </h2> <c:set var="a1" value="我是一只小花猫" scope="application"></c:set> <h2>@1获取数据用EL表达式</h2> ${a1 } <br> <h2>@2指定作用域pageScope sessionScope</h2> <c:set var="b" value="我是一只小花狗" ></c:set> ${pageScope.b } <br> <!-- value 省去 --> <h2>@3省去 value的值 </h2> <c:set var="c" scope="session">Hellow World Jsp</c:set> <h2>指定作用域</h2> <br> ${sessionScope.c } <br> <h2>@4跳转作用域来获取数据</h2> <c:set scope="application" var="apple" value="${a1 }"></c:set> $(applicationScope.apple)<br> <hr> <h2>@5删除数据内容</h2> <c:remove var="c"/> ${empty(c) } <!-- out 输出数据 通过EL表达式 --> <h2>@ 6out 输出数据 通过EL表达式</h2> <c:out value="${c }"></c:out> <br> <c:out value="${b }"></c:out> </body> </html>
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%> <%@taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %> <!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <style type="text/css"> *{ color: black; font-size: 34px; font-weight: bold; } h1{ color: yellow; background-color: black; } h2{ color: white; background-color: black; } </style> <title>JSTL标签库的使用一通用标签库2</title> </head> <body> <h1 style="color: red; font-size: 45px;text-align: center;"> 标签库和JSp动作合起来使用 </h1> <h2 style="align-content: center; text-align: center;">JSTL标签库的使用二通用标签库2</h2> <jsp:useBean id="car" class="com.abc.Car" scope="page"></jsp:useBean> <c:set target="${car }" property="name" value="红旗"></c:set> <c:set target="${car }" property="price" value="36000"></c:set> <c:set target="${car }" property="type" value="pink"></c:set> ${car.name }<br> ${car.price }<br> ${car.type}<br> <hr> </body> </html>
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%> <%@taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %> <!DOCTYPE html> <html> <head> <style type="text/css"> *{ color: black; font-size: 34px; font-weight: 900px; } h1{ color: yellow; background-color: black; } h2{ color: white; background-color: black; } </style> <meta charset="UTF-8"> <title>JSTL标签库的使用一流程标签库</title> </head> <body> <article> <h1> 表达式标签:out set remove 流程标签 if choose when otherwise 循环标签 forEach forTokens url 标签 import url redirect parm </h1> <h2 style="align-content: center;">JSTL标签库的使用三流程标签库</h2> <hr> </article> <!-- 条件标签库 --> <!-- 判断一个数的基数 和偶数--> <h2>判断一个数的基数 和偶数</h2> <c:set var="num" value="346" scope="page"></c:set> <c:set var="nums" value="347" scope="page"></c:set> <h3>test:是表达式,最后结果为true,false</h3> <c:if test="${num%2 ==0}"> <h3 style="color: red;">这数为偶数偶数</h3> </c:if> <c:if test="${num%2 !=0}"> <h3 style="color: green;">这数为奇数</h3> </c:if> <hr> <h2>方法二计算了一次</h2> <c:if test="${nums%2 ==0}" var="jieguo" scope="page"></c:if> <c:if test="${jieguo}"> <h3 style="color: red;">这数为偶数</h3> </c:if> <c:if test="${!jieguo}"> <h3 style="color: green;">这数为奇数</h3> </c:if> <hr> <!--判断月份 --> <c:set var="month" value="13" scope="session"></c:set> <c:set var="months" value="8" scope="session"></c:set> <c:choose> <c:when test="${month>=1 && month<=3 }"> <h4 style="color: gray;">第一季节</h4> </c:when> <c:when test="${month>=4 && month<=6 }"> <h4 style="color: red;">第二季节</h4> </c:when> <c:when test="${month>=7 && month<=9 }"> <h4 style="color: green;">第三季节</h4> </c:when> <c:when test="${month>=10 && month<=12 }"> <h4 style="background-color: black;color: pink; font-size: 50px">第四季节冬季</h4> </c:when> <c:otherwise> <h1>月份是有误的</h1> </c:otherwise> </c:choose> <c:choose> <c:when test="${months>=1 && months<=3 }"> <h4 style="color: gray;">第一季节</h4> </c:when> <c:when test="${months>=4 && months<=6 }"> <h4 style="color: red;">第二季节</h4> </c:when> <c:when test="${months>=7 && months<=9 }"> <h4 style="color:red; background-color: black;">第三季节</h4> </c:when> <c:when test="${months>=10 && months<=12 }"> <h4 style="background-color: black;color: pink; font-size: 50px">第四季节冬季</h4> </c:when> <c:otherwise> <h1>月份是有误的</h1> </c:otherwise> </c:choose> </body> </html>
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%> <%@taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %> <!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <style type="text/css"> *{ color: black; font-size: 34px; font-weight: bold; } h2{ color: white; background-color: black; } </style> <title>循环标签 forEach</title> </head> <body> <h2> 表达式标签:out set remove 流程标签 if choose when otherwise 循环标签 forEach forTokens url 标签 import url redirect parm </h2> <h2>for循环标签</h2> <% String [] name ={"编号1001小碗","编号1002小花","编号1003小白","编号1004小坡","编号1005小(>^ω^<)喵", "编号1006消费", "编号1007呼叫", "编号1008hello", "编号1009need发", "编号1010你好", "编号1001011细看" ,"编号10012加油", "编号10013明白"}; application.setAttribute("name", name); String [] names ={"小白","小坡","小(>^ω^<)喵","消费","呼叫","hello","need发","你好","细看","小胡"}; application.setAttribute("names", names); %> ${names[0]},${names[1]},${names[2]},${names[3]},${names[4]}<br> <h2> forEach标签属性: @1 items:要循环数据的集合or 数组。 @2 var:定义变量,用于存放每一次循环从数组中拿数据。 @3 begin从第几个数据开始循环。 @4 end控制下标在第几项结束。 @5 step增加的步长。 @6 varStatus设置没一次循环的次数 </h2> <c:forEach items="${names}" var="nb" step="2" varStatus="s"> <c:if test="${s.count %2 !=0}"> 存放每一次循环从数组中拿数据${nb }<br> </c:if> </c:forEach> <hr> <c:forEach items="${name}" var="nbs" begin="2" end="10" > 存放每一次循环从数组中拿数据${nbs }<br> </c:forEach> </body> </html>
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%> <%@taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %> <!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <style type="text/css"> *{ color: black; font-size: 30px; font-weight: bold; } h2{ color: white; background-color: black; } </style> <title>forTokens</title> </head> <body> <c:forTokens items="脸色,换货单号的,kjdkdkdk,hhsdhdj,哈哈哈" delims="," var="str"> <p style="color: green; background-color: black;">被分开的数据以,分开: ${str }</p> </c:forTokens> <br> <c:forTokens items="脸色/,换货/单号的/,kjdkd/kd/k,hhsd/hdj,哈哈哈" delims="/" var="str1"> <p style="color: red; background-color: black;">被分开的数据以/分开: ${str1 }</p> </c:forTokens> <hr> <c:forTokens items="hellow-orld-色-而退-京东快-递开-的亟-待解-决的撒娇-的角度-记得-看恢-复上-课了" delims="-" var="str2"> <p style=" background-color: green; color: pink;">被分开的数据以-分开: ${str2 }</p> </c:forTokens> <hr> <c:forTokens items="h*ell*ow-*orl*d-色-而*退-京东*快-递*开-的*亟-待*解-*决的*撒娇-的*角度-记*得-看恢*-复*上-*课*了*" delims="*" var="str2"> <p style=" background-color: yellow; color: pink;">被分开的数据以*分开: ${str2 }</p> </c:forTokens> </body> </html>
模块十二java与mysql
package com.db.text; import java.io.InputStream; import java.sql.Connection; import java.sql.PreparedStatement; import java.util.List; import java.util.Properties; import javax.sql.DataSource; import org.junit.Test; import org.springframework.jdbc.core.JdbcTemplate; import com.alibaba.druid.pool.DruidDataSourceFactory; import com.sun.javafx.collections.MappingChange.Map; public class JDBCTemplateDemo { public static JdbcTemplate jt =null; /** * sping框架 */ static { //建立连接 InputStream is=DruidDemo.class .getClassLoader().getResourceAsStream("com/db/text/druid.properties"); Properties properties =new Properties(); try { properties.load(is); DataSource ds=DruidDataSourceFactory.createDataSource(properties); jt=new JdbcTemplate(ds); //并不是断开连接,而是将用完的对象放入连接池 } catch (Exception e) { e.printStackTrace(); } } @Test public void test1() { //增加语句 String sql="insert into tb_students(name,age) VALUES(?,?)"; int i= jt.update(sql,"我是mysql",25); if(i>0) { System.out.println("数据增加成功"); } } //修改数据 @Test public void text2() { String sql="update tb_students set age=? where id=?"; int i=jt.update(sql ,24,23); if(i>0) { System.out.println("数据修改成功"); } } @Test public void text3() { String sql="DELETE FROM `studentdb`.`tb_student` WHERE ` id` = ?"; int i=jt.update(sql ,1); if(i>0) { System.out.println("数据删除成功"); } } @Test public void text4() { String sql="select *from tb_students where id=?"; Map<String, Object> map = (Map<String, Object>) jt.queryForMap(sql, 2); System.out.println(map); } @Test public void test5() { String sql="select *from tb_students"; List<java.util.Map<String, Object>> olList =jt.queryForList(sql); olList.forEach(map->System.out.println(map)); } }
回顾了之前学习的重要代码。之后我会综合自己所学内容,将mysql,sevlect,jsp,html,javascript,jquery,csss3.前端+后端+数据库综合起来使用。还有一些框架将使用到项目中。一个项目需要不断的去构思。