第75节:Java的中的JSP,EL和JSTL
第75节:java中的jsp,el和jstl
哭吧看不完的!!!
cookie
和`session
请求转发和重定向的区别:
- 地址不一样
- 请求次数也不一样
- 数据无法传递
4.跳转范围有限制 - 效率
请求转发请求1次,只能对当前项目跳转,重定向请求2次.重定向是无法传递的,重定向对跳转范围没有限制.
cookie
是服务器发送给客户端,存储在客户端的小数据.发送cookie
:
cookie cookie = new cookie("key", value"); response.addcookie(cookie); 服务器返回cookie给客户端 // 响应头 set-cookie: a=b
接收cookie
cookie[] cookies = request.getcookies(); 客户端提交数据的cookie // cookie: a=b;c=d;
cookie
分会话cookie
和持久cookie
关闭cookie
,可以关闭浏览器.
持久的cookie
,在一段时间内有效
cookie cookie = new cookie("a","b"); cookie.setmaxage(); // 秒 response.addcookie(cookie); cookie.setdomain(".dashucoding.com"); // 只有带上这个域名的时候,才会有cookie // 例如:www.dashucoding.com cookie..setpath("/demo"); // 要进行访问上面的路径才会带cookie http://localhost:8080/demo
移除cookie
cookie cookie = new cookie("a","b"); cookie.setmaxage(60*60*24); response.addcookie(cookie); // 获取以前cookie,设置有效期 cookie[] cookies = request.getcookies(); cookie cookie = cookieutil.findcookie(cookies,"a"); cookie.setmaxage(0); reponse.addcookie(cookie);
cookie
是存在客户端的.
可以创建一个新的cookie
去替换
cookie cookie = new cookie("a","dashu"); cookie.setmaxage(0); response.addcookie(cookie);
session
是基于cookie
的一种会话技术.cookie
的安全隐患,是把数据存放在客户端,下次访问时,带上这个数据,服务端就知道客户端是谁.
session
的数据是存放在服务端.
session
对应sessionid
传递给客户端,是通过cookie
传递的.只要有sessiondi
,就可以获取以前的数据.
httpsession session = request.getsession(); session.setattribute(); sesssion.getattribute();
package com.dashucoding.servlet; import java.io.ioexception; import javax.servlet.servletexception; import javax.servlet.http.httpservlet; import javax.servlet.http.httpservletrequest; import javax.servlet.http.httpservletresponse; import javax.servlet.http.httpsession; /** * servlet implementation class demo01 */ public class demo01 extends httpservlet { protected void doget(httpservletrequest request, httpservletresponse response) throws servletexception, ioexception { // todo auto-generated method stub httpsession session = request.getsession(); // 得到会话id session.getid(); // 存值 //session.setattribute(name, value); // 取值 //session.getattribute(name); // 移植 //session.removeattribute(name); } protected void dopost(httpservletrequest request, httpservletresponse response) throws servletexception, ioexception { // todo auto-generated method stub doget(request, response); } }
session
创建:
request.getsession
销毁
关闭服务器,或自动会话过期,默认时间为30分钟.
在进行访问浏览器时,再次重启是无法获取以前的数据的,因为
sessionid
是通过cookie
来传递的,cookie
没有设置有效期,关闭后,就cookie
删除了,同时cookie
带过来sessionid
同样也没有了.
手动设置cookie
string id = request.getsession().getid(); cookie cookie = new cookie("jsessionid",id); cookie.setmaxage(60*60*24*7); response.addcookie(cookie);
jsp
和el
和jstl
什么是jsp
jsp
就是一个网页而已,或者是一个java
类,继承了servlet
,所以jsp
是一个servlet
.
jsp
设计目的是因为html
是显示静态内容,有时网页要一些动态数据.html
是不支持java
代码,jsp
支持java
代码.
写法
指令 <%@ %> language contenttype内容类型 content-type="text/html;charset=utf-8" pageencoding jsp内容编码
extends="httpjspbase" 用于指定jsp翻译成java文件后,继承的父类是谁 import导包使用,一般不用手写 session true or false errorpage 错误的页面. iserrorpage="true" 显示错误 errorpage="error.jsp" 呈现错误 errorpage 值需要给错误的页面路径 include <%-- <%@ include file="other02.jsp"%> --%> 把另外一个页面的内容拿过来 <%-- <%@ taglib prefix="" uri=""%> --%> url标签库的路径 prefix别名
include
和forward
<%-- <jsp:include page=""></jsp:include> <jsp:param value="" name=""/> <jsp:forward page=""></jsp:forward> --%>
<%-- <jsp:include page="other02.jsp"></jsp:include> --%> <%-- <jsp:forward page="other02.jsp"></jsp:forward> 等同于以下代码 --%> <% //请求转发 //request.getrequestdispatcher("other02.jsp").forward(request, response); %> <jsp:forward page="other02.jsp"> <jsp:param value="beijing" name="address"/> </jsp:forward>
jsp: param <jsp:forward page="other02.jsp"> <jsp:param value="beijing" name="address"/> </jsp:forward> <%= request.getparameter("address")%>
小结
什么是jsp
为什么会有jsp
三大指令集
page 有什么用,那么怎么用,有哪些常用的属性 include 有什么用,那么怎么用 taglib 有什么用,怎么用 jsp动作标签 jsp:forword jsp:include jsp:param
jsp
的内置对象
四个作用域 pagecontext request session appiication
jsp
内置对象
内置对象是在jsp
页面中使用的这些对象,不用创建
pagecontext request session application exception out page config response
application: servletcontext config: servletconfig out: jspwriter page: object pagecontext: pagecontext request: httpservletrequest session: httpsession
final javax.servlet.jsp.pagecontext pagecontext; javax.servlet.http.httpsession session = null; final javax.servlet.servletcontext application; final javax.servlet.servletconfig config; javax.servlet.jsp.jspwriter out = null; final java.lang.object page = this; javax.servlet.jsp.jspwriter _jspx_out = null; javax.servlet.jsp.pagecontext _jspx_page_context = null; request, response
四个作用域
pagecontext request session application
作用域,就是这个对象可以在哪用,对象可以存值,取值范围限定.
作用的对象是不一样的
setattribute getattribute
pagecontext:作用域只能在当前页面,pagecontext request:作用域限于一次请求 只要服务器做出反应,域中的值就没有了httpservletrequest session:限于一次会话,第二次会话就没了,httpsession application:都有,都可以访问,只有服务器关闭后就不能访问了.->servletcontext 一个工程只能有一个
exception -> throwable config -> servletconfig page -> object -> 当前类的实例 response -> httpservletresponse out jsp -> jspwriter
out response.getwriter
out
对象输出的内容是放到response
的缓冲区内的,先输出response
本身的内容,然后才是out
里面的内容.
exception -> throwable page -> object -> 一般就是jsp翻译成java类的实例对象 -> this -> 当前实例类 config -> servletconfig
out -> jspwriter response -> httpservletresponse
pagecontext -> pagecontext: 作用域当前页面 request -> httpservletreques: 作用域限于一次请求 session -> httpsession -> 作用域限于一次会话 application -> servletcontext 整个工程可以访问,服务器关闭后就不能进行访问了
pagecontext 也可以获取其他8个内置对象
el
表达式:
是什么,怎么用,也有内置对象?
// 作用域 pagescope requestscope sessionscope applicationscope
// 请求头 header headervalues
参数 param params
el
表达式
简化jsp
中java
的代码.
${ 表达式 }
取值方式:
<% string [] a = {"aa","bb","cc","dd"}; pagecontext.setattribute("array", a); %> <% user user = new user {"zhangsan",18}; session.setattribute("u", user); %> ${u.name}, ${u.age}
<%@page import="com.dashucoding.domain.user"%> <%@ 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> </head> <body> 从域中取值。 得先存值。 <% //pagecontext.setattribute("name", "zhangsan"); session.setattribute("name", "lisi..."); %> <br>直接指定说了,到这个作用域里面去找这个name<br> ${ pagescope.name } <br>//先从page里面找,没有去request找,去session,去application <br> ${ name } <br>指定从session中取值<br> ${ sessionscope.name } <br>---------------------------------------------<br> <% user user = new user("zhangsan",18); session.setattribute("u", user); %> ${ u.name } , ${ u.age } ${ a > b} ${ a gt b } ${ empty u } </body> </html>
package com.dashucoding.domain; public class user { private string name; private int age; public user(string name, int age) { super(); this.name = name; this.age = age; } public string getname() { return name; } public void setname(string name) { this.name = name; } public int getage() { return age; } public void setage(int age) { this.age = age; } }
<%@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> </head> <body> <% pagecontext.setattribute("name", "page"); request.setattribute("name", "request"); session.setattribute("name", "session"); application.setattribute("name", "application"); %> 按普通手段取值<br> <%= pagecontext.getattribute("name")%> <%= request.getattribute("name")%> <%= session.getattribute("name")%> <%= application.getattribute("name")%> <br>使用el表达式取出作用域中的值<br> ${ pagescope.name } ${ requestscope.name } ${ sessionscope.name } ${ applicationscope.name } ${name } <br>-----------------------------<br> <% string [] a = {"aa","bb","cc","dd"}; pagecontext.setattribute("array", a); %> 使用el表达式取出作用域中数组的值<br> ${array[0] } , ${array[1] },${array[2] },${array[3] } <br>-------------集合数据----------------<br> <% list list = new arraylist(); list.add("11"); list.add("22"); list.add("33"); list.add("44"); //pagecontext.setattribute("li", list); session.setattribute("li", list); %> 使用el表达式取出作用域中集合的值<br> ${li[0] } , ${li[1] },${li[2] },${li[7] } <br>-------------map数据----------------<br> <% map map = new hashmap(); map.put("name", "zhangsna"); map.put("age",18); map.put("address","北京.."); map.put("address.aa","深圳.."); //pagecontext.setattribute("map", map); application.setattribute("m", map); %> 使用el表达式取出作用域中map的值<br> ${applicationscope.m.name } , ${m.age } , ${m.address } , ${m["address.aa"] } </body> </html>
el表达式隐式对象
11个内置对象
${ }
pagecotext pagescope requestscope sessionscope applicationscope
请求参数 param paramvalues 请求头 header headervalues cookie initparam初始化参数
pagecontext是pagecontext实例,其他都是map类.
el内置对象
// 作用域 pagescope requestscope sessionscope applicationscope // 请求头 header headervalues // 请求参数 param params cookie 全局初始化参数 initparam pagecontext
引入
<%@ 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> </head> <body> 这是el03页面 <jsp:forward page="el04.jsp"> <jsp:param value="beijing...." name="address"/> </jsp:forward> </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> </head> <body> 这是el04页面<br> <%=request.getparameter("address") %> <br> 使用el表达式获取这个参数 <%-- response.addcookie(new cookie("name","value")); ${cookie.name } --%> ${param.address } </body> </html>
小结案例
<%@ page language="java" contenttype="text/html; charset=utf-8" pageencoding="utf-8" %> <%-- <%@ include file="other02.jsp"%> --%> <%-- <%@ taglib prefix="" uri=""%> --%> <!doctype html> <html> <head> <meta charset="utf-8"> <title>insert title here</title> </head> <body> <%-- <jsp:include page="other02.jsp"></jsp:include> --%> 这是other页面的内容. </body> </body> </html>
<%@ page language="java" contenttype="text/html; charset=utf-8" pageencoding="utf-8" iserrorpage="true"%> <!doctype html> <html> <head> <meta charset="utf-8"> <title>insert title here</title> </head> <body> <h3>这是other022222的内容</h3> <br>收到的参数是:<br> <%= request.getparameter("address")%> <% %> </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> </head> <body> 这是other03的页面 <br>使用作用域来存储数据<br> <% pagecontext.setattribute("name", "page"); request.setattribute("name", "request"); session.setattribute("name", "session"); application.setattribute("name", "application"); %> 取出四个作用域中的值<br> <%=pagecontext.getattribute("name")%> <%=request.getattribute("name")%> <%=session.getattribute("name")%> <%=application.getattribute("name")%> <!-- //跳转到下一个界面去了 --> <% //请求转发. 一次请求 //request.getrequestdispatcher("other04.jsp").forward(request, response); //重定向 2次请求 response.sendredirect("other04.jsp"); %> </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> </head> <body> <h3>这是04的页面</h3><br> 取出四个作用域中的值<br> <%=pagecontext.getattribute("name")%> <%=request.getattribute("name")%> <%=session.getattribute("name")%> <%=application.getattribute("name")%> </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> </head> <body> 这是other05的页面<br> <% out.write("这是使用out对象输出的内容"); %> <br> <% response.getwriter().write("这是使用response对象输出的内容"); %> </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> </head> <body> <%-- <jsp:include page=""></jsp:include> <jsp:param value="" name=""/> <jsp:forward page=""></jsp:forward> --%> 这是jsp_action的页面. <%-- <jsp:include page="other02.jsp"></jsp:include> --%> <%-- <jsp:forward page="other02.jsp"></jsp:forward> 等同于以下代码 --%> <% //请求转发 //request.getrequestdispatcher("other02.jsp").forward(request, response); %> <jsp:forward page="other02.jsp"> <jsp:param value="beijing" name="address"/> </jsp:forward> </body> </html>
<%@ page language="java" contenttype="text/html; charset=utf-8" pageencoding="utf-8" iserrorpage="true"%> <!doctype html> <html> <head> <meta charset="utf-8"> <title>insert title here</title> </head> <body> 服务器正在维护,请稍后访问.. <%-- <%=exception.tostring() %> --%> </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> </head> <body> <% pagecontext.setattribute("name", "page"); request.setattribute("name", "request"); session.setattribute("name", "session"); application.setattribute("name", "application"); %> 按普通手段取值<br> <%= pagecontext.getattribute("name")%> <%= request.getattribute("name")%> <%= session.getattribute("name")%> <%= application.getattribute("name")%> <br>使用el表达式取出作用域中的值<br> ${ pagescope.name } ${ requestscope.name } ${ sessionscope.name } ${ applicationscope.name } ${name } <br>-----------------------------<br> <% string [] a = {"aa","bb","cc","dd"}; pagecontext.setattribute("array", a); %> 使用el表达式取出作用域中数组的值<br> ${array[0] } , ${array[1] },${array[2] },${array[3] } <br>-------------集合数据----------------<br> <% list list = new arraylist(); list.add("11"); list.add("22"); list.add("33"); list.add("44"); //pagecontext.setattribute("li", list); session.setattribute("li", list); %> 使用el表达式取出作用域中集合的值<br> ${li[0] } , ${li[1] },${li[2] },${li[7] } <br>-------------map数据----------------<br> <% map map = new hashmap(); map.put("name", "zhangsna"); map.put("age",18); map.put("address","北京.."); map.put("address.aa","深圳.."); //pagecontext.setattribute("map", map); application.setattribute("m", map); %> 使用el表达式取出作用域中map的值<br> ${applicationscope.m.name } , ${m.age } , ${m.address } , ${m["address.aa"] } </body> </html>
jstl介绍
jstl是什么,用来做什么. el只能取值操作 jstl遍历的效果
jstl. jsp standard tag library jsp标签库 简化jsp,与el表达式配合
// 使用jstl <%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<c:set var = "name" value="dashu"></c:set> ${name} <c:set var = "name" value="dashu" scope="session"></c:set> ${sessionscope.name} 默认存储的是page <c:set var = "age" value="12" ></c:set> <c:if text="${age>10}"> age大于10 </c:if> <c:foreach begin="1" end="10" var="i" step="2"> ${i} </c:foreach>
学生信息管理系统
login.jsp -> 一个页面 login_servlet -> 一个页面 基本操作页面 -> 查看学生列表 stu_list.jsp 获取信息 查询数据库 判断账号信息 正确前往下一页 错误,登录失败
案例:
package com.dashucoding.dao; import java.util.list; import com.dashucoding.domain.student; public interface studao { /** * 查询出来所有的学生信息 * @return list集合 */ list<student> findall(); }
package com.dashucoding.dao; /* * 定义 * 该dao定义了对用户表的访问规则 * */ public interface userdao { /** * 这里简单就返回一个boolean类型, 成功或者失败即可。 * * 但是开发的时候,登录的方法,一旦成功。这里应该返回该用户的个人信息 * @param username * @param password * * @return true : 登录成功, false : 登录失败。 */ boolean login(string username , string password); }
package com.dashucoding.dao.impl; import java.sql.connection; import java.sql.preparedstatement; import java.sql.resultset; import java.sql.sqlexception; import java.util.arraylist; import java.util.list; import com.dashucoding.dao.studao; import com.dashucoding.domain.student; import com.dashucoding.util.jdbcutil; public class studaoimpl implements studao{ @override public list<student> findall() { list<student> list = new arraylist<student>(); connection conn = null; preparedstatement ps = null; resultset rs = null; try { //1. 得到连接对象 conn = jdbcutil.getconn(); string sql = "select * from t_stu"; ps = conn.preparestatement(sql); rs = ps.executequery(); //数据多了,用对象装, 对象也多了呢? 用集合装。 while(rs.next()){ //10 次 ,10个学生 student stu = new student(); stu.setid(rs.getint("id")); stu.setage(rs.getint("age")); stu.setname(rs.getstring("name")); stu.setgender(rs.getstring("gender")); stu.setaddress(rs.getstring("address")); list.add(stu); } } catch (sqlexception e) { e.printstacktrace(); }finally { jdbcutil.release(conn, ps, rs); } return list; } }
package com.dashucoding.dao.impl; import java.sql.connection; import java.sql.preparedstatement; import java.sql.resultset; import java.sql.sqlexception; import com.dashucoding.dao.userdao; import com.dashucoding.util.jdbcutil; public class userdaoimpl implements userdao { @override public boolean login(string username , string password) { connection conn = null; preparedstatement ps = null; resultset rs = null; try { //1. 得到连接对象 conn = jdbcutil.getconn(); string sql = "select * from t_user where username=? and password=?"; //2. 创建ps对象 ps = conn.preparestatement(sql); ps.setstring(1, username); ps.setstring(2, password); //3. 开始执行。 rs = ps.executequery(); //如果能够成功移到下一条记录,那么表明有这个用户。 return rs.next(); } catch (sqlexception e) { e.printstacktrace(); }finally { jdbcutil.release(conn, ps, rs); } return false; } }
package com.dashucoding.domain; public class student { private int id ; private string name; private int age ; private string gender; private string address; public int getid() { return id; } public void setid(int id) { this.id = id; } public string getname() { return name; } public void setname(string name) { this.name = name; } public int getage() { return age; } public void setage(int age) { this.age = age; } public string getgender() { return gender; } public void setgender(string gender) { this.gender = gender; } public string getaddress() { return address; } public void setaddress(string address) { this.address = address; } }
package com.dashucoding.servlet; import java.io.ioexception; import java.util.list; import javax.servlet.servletexception; import javax.servlet.http.httpservlet; import javax.servlet.http.httpservletrequest; import javax.servlet.http.httpservletresponse; import com.dashucoding.dao.studao; import com.dashucoding.dao.userdao; import com.dashucoding.dao.impl.studaoimpl; import com.dashucoding.dao.impl.userdaoimpl; import com.dashucoding.domain.student; /** * servlet implementation class loginservlet */ public class loginservlet extends httpservlet { protected void doget(httpservletrequest request, httpservletresponse response) throws servletexception, ioexception { // todo auto-generated method stub // 提交的数据有可能有中文 request.setcharacterencoding("utf-8"); response.setcontenttype("text/html;charset=utf-8"); // 获取客户端提交的信息 string username = request.getparameter("username"); string password = request.getparameter("password"); // 去访问dao , 看看是否满足登录 userdao dao = new userdaoimpl(); boolean issuccess = dao.login(username, password); if (issuccess) { // response.getwriter().write("登录成功."); // 请求转发 // 查询所有的学生信息 studao studao = new studaoimpl(); list<student> list = studao.findall(); // 先把这个集合存到作用域 request.getsession().setattribute("list", list); // 重定向 response.sendredirect("stu_list.jsp"); } else { response.getwriter().write("用户名或者密码错误!"); } } protected void dopost(httpservletrequest request, httpservletresponse response) throws servletexception, ioexception { // todo auto-generated method stub doget(request, response); } }
package com.dashucoding.util; import java.io.fileinputstream; import java.io.inputstream; import java.sql.connection; import java.sql.drivermanager; import java.sql.resultset; import java.sql.sqlexception; import java.sql.statement; import java.util.properties; public class jdbcutil { static string driverclass = null; static string url = null; static string name = null; static string password= null; static{ try { //1. 创建一个属性配置对象 properties properties = new properties(); // inputstream is = new fileinputstream("jdbc.properties"); //使用类加载器,去读取src底下的资源文件。 后面在servlet inputstream is = jdbcutil.class.getclassloader().getresourceasstream("jdbc.properties"); //导入输入流。 properties.load(is); //读取属性 driverclass = properties.getproperty("driverclass"); url = properties.getproperty("url"); name = properties.getproperty("name"); password = properties.getproperty("password"); } catch (exception e) { e.printstacktrace(); } } /** * 获取连接对象 * @return */ public static connection getconn(){ connection conn = null; try { class.forname(driverclass); //静态代码块 ---> 类加载了,就执行。 java.sql.drivermanager.registerdriver(new driver()); //drivermanager.registerdriver(new com.mysql.jdbc.driver()); //drivermanager.getconnection("jdbc:mysql://localhost/test?user=monty&password=greatsqldb"); //2. 建立连接 参数一: 协议 + 访问的数据库 , 参数二: 用户名 , 参数三: 密码。 conn = drivermanager.getconnection(url, name, password); } catch (exception e) { e.printstacktrace(); } return conn; } /** * 释放资源 * @param conn * @param st * @param rs */ public static void release(connection conn , statement st , resultset rs){ closers(rs); closest(st); closeconn(conn); } public static void release(connection conn , statement st){ closest(st); closeconn(conn); } private static void closers(resultset rs){ try { if(rs != null){ rs.close(); } } catch (sqlexception e) { e.printstacktrace(); }finally{ rs = null; } } private static void closest(statement st){ try { if(st != null){ st.close(); } } catch (sqlexception e) { e.printstacktrace(); }finally{ st = null; } } private static void closeconn(connection conn){ try { if(conn != null){ conn.close(); } } catch (sqlexception e) { e.printstacktrace(); }finally{ conn = null; } } }
<%@ 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> </head> <body> <h2>欢迎学生管理系统</h2> <form action="loginservlet" method="post"> 账号: <input type="text" name="username" /><br> 密码: <input type="password" name="password" /><br> <input type="submit" value="登录"> </form> </body> </html>
<%@ page language="java" contenttype="text/html; charset=utf-8" pageencoding="utf-8"%> <%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%> <!doctype html> <html> <head> <meta charset="utf-8"> <title>学生信息管理系统</title> </head> <body> <br>学生列表<br> <table border="1" width="700"> <tr align="center"> <td>编号</td> <td>姓名</td> <td>年龄</td> <td>性别</td> <td>住址</td> <td>操作</td> </tr> <c:foreach items="${list}" var="stu"> <c:if test=""></c:if> <tr align="center"> <td>${stu.id }</td> <td>${stu.name }</td> <td>${stu.age }</td> <td>${stu.gender }</td> <td>${stu.address }</td> <td><a href="#">更新</a> <a href="#">删除</a></td> </tr> </c:foreach> </table> </body> </html>
分析
login.jsp -> loginservlet -> 获取登录信息 创建用户表, 创建userdao 创建userdaoimple loginservlet里面访问userdao,判断登录, 创建stu_list.jsp,让登录进入 创建学生表 定义dao,studao studao, studaoimpl
数据库
小结
jsp
jsp -> 九个内置对象 page include taglib <jsp:include> <jsp:forward> <jsp:param> el -> 11个内置对象 ${ 表达式 } 取4个作用域中的值 pagecontext pagescope requestscope sessionscope applicationscope header headervalues param paramvalues cookie initparam jstl <c:set> <c:if> <c:foreach>
如果看了觉得不错
点赞!转发!
达叔小生:往后余生,唯独有你
you and me, we are family !
90后帅气小伙,良好的开发习惯;独立思考的能力;主动并且善于沟通
简书博客: 达叔小生
结语
- 下面我将继续对 其他知识 深入讲解 ,有兴趣可以继续关注
- 小礼物走一走 or 点赞
上一篇: SpringBoot中的定时任务与Quartz的整合
下一篇: 浅谈网站URL的类型及SEO优化点
推荐阅读