1.1 创建如下oracle数据库脚本

 drop sequence seq_stu;

 create sequence SEQ_STU
minvalue 1
maxvalue 999999999999999999999999999
start with 1
increment by 1
cache 20; drop table student; create table STUDENT
(
sid NUMBER not null,
sname VARCHAR2(20) not null,
password VARCHAR2(20) default '',
sex VARCHAR2(10) default '女',
cid NUMBER not null
);
alter table STUDENT
add constraint pk_SID primary key (SID); alter table STUDENT
add constraint CK_STUDENT_CID
check (cid between 1 and 50); insert into STUDENT (sid, sname, password, sex, cid)
values (SEQ_STU.NEXTVAL, '潜逃', '', '男', 1);
insert into STUDENT (sid, sname, password, sex, cid)
values (SEQ_STU.NEXTVAL, '周强', '', '男', 1);
insert into STUDENT (sid, sname, password, sex, cid)
values (SEQ_STU.NEXTVAL, '薛东', '', '男', 1);
insert into STUDENT (sid, sname, password, sex, cid)
values (SEQ_STU.NEXTVAL, '帅天威', '', '男', 2);
insert into STUDENT (sid, sname, password, sex, cid)
values (SEQ_STU.NEXTVAL, '汤帅', '', '男', 2);
insert into STUDENT (sid, sname, password, sex, cid)
values (SEQ_STU.NEXTVAL, '刘亮', '', '男', 2);
insert into STUDENT (sid, sname, password, sex, cid)
values (SEQ_STU.NEXTVAL, '李杰', '', '男', 3);
insert into STUDENT (sid, sname, password, sex, cid)
values (SEQ_STU.NEXTVAL, '唐龙', '', '男', 3);
insert into STUDENT (sid, sname, password, sex, cid)
values (SEQ_STU.NEXTVAL, '胡强', '', '男', 3);
insert into STUDENT (sid, sname, password, sex, cid)
values (SEQ_STU.NEXTVAL, '李文宝', '', '男', 4);
insert into STUDENT (sid, sname, password, sex, cid)
values (SEQ_STU.NEXTVAL, '程秀秀', '', '女', 4);
insert into STUDENT (sid, sname, password, sex, cid)
values (SEQ_STU.NEXTVAL, '陆羽', '', '男', 4);
insert into STUDENT (sid, sname, password, sex, cid)
values (SEQ_STU.NEXTVAL, 'holly', '', '女', 4);
commit; --只修改列表 列名重命名
alter table student rename column ssex to sex; select * from student; commit;

student.sql

1.2 创建如下项目结构

1.3 在项目的src根目录下创建hibernate.cfg.xml

 <?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-configuration PUBLIC "-//Hibernate/Hibernate Configuration DTD 3.0//EN" "http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd" >
<hibernate-configuration>
<session-factory>
<property name="connection.driver_class">oracle.jdbc.driver.OracleDriver</property>
<property name="connection.url">jdbc:oracle:thin:@127.0.0.1:1521:orcl</property>
<property name="connection.username">holly</property>
<property name="connection.password">sys</property>
<property name="dialect">org.hibernate.dialect.Oracle10gDialect</property>
<property name="show_sql">true</property>
<property name="format_sql">true</property>
<mapping resource="com/entity/Student.hbm.xml"/>
</session-factory>
</hibernate-configuration>

hibernate.cfg.xml

1.4 在项目的src下的com.entity包下创建Student.java

 package com.entity;

 public class Student {
private Integer sid;
private String sname;
private String password;
private String sex;
private Integer cid; public Student() {
}
public Student(Integer sid, String sname, String password, String sex,
Integer cid) {
this.sid = sid;
this.sname = sname;
this.password = password;
this.sex = sex;
this.cid = cid;
}
public Student(String sname, String password, String sex,
Integer cid) {
this.sname = sname;
this.password = password;
this.sex = sex;
this.cid = cid;
}
public Integer getSid() {
return sid;
}
public void setSid(Integer sid) {
this.sid = sid;
}
public String getSname() {
return sname;
}
public void setSname(String sname) {
this.sname = sname;
}
public String getPassword() {
return password;
}
public void setPassword(String password) {
this.password = password;
}
public String getSex() {
return sex;
}
public void setSex(String sex) {
this.sex = sex;
}
public Integer getCid() {
return cid;
}
public void setCid(Integer cid) {
this.cid = cid;
}
@Override
public String toString() {
return "Student [cid=" + cid + ", password=" + password + ", sex="
+ sex + ", sid=" + sid + ", sname=" + sname + "]";
} }

Student.java

1.5 在项目的src下的com.entity包下创建Student.hbm.xml映射文件

 <?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN" "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd" >
<hibernate-mapping>
<class name="com.entity.Student" table="STUDENT">
<id name="sid" type="java.lang.Integer" column="SID">
<generator class="sequence">
<param name="sequence">SEQ_STU</param>
</generator>
</id>
<property name="sname" type="java.lang.String" column="SNAME"/>
<property name="password" type="java.lang.String" column="PASSWORD"/>
<property name="sex" type="java.lang.String" column="SEX"/>
<property name="cid" type="java.lang.Integer" column="CID"/>
</class>
</hibernate-mapping>

Student.hbm.xml

1.6 在项目的src下的com.page包下创建Page.java

 package com.page;

 public class Page {
private Integer pagesize; //页面大小
private Integer pageno; //当前页
private Integer startrow; //起始行
private Integer totalpage; //总页数
private Integer totalcount; //总条数 public Page() {
}
public Page(Integer pageSize, Integer pageNo, Integer totalCount) {
this.pagesize = pageSize; //页面大小
this.pageno = pageNo; //当前页
this.totalcount = totalCount; //计算总条数
this.setStartrow(pageNo, pageSize); //计算起始行
this.setTotalpage(totalCount, pageSize); //计算总页数
}
public Integer getPagesize() {
return pagesize;
}
public void setPagesize(Integer pageSize) {
this.pagesize = pageSize;
}
public Integer getPageno() {
return pageno;
}
public void setPageno(Integer pageNo) {
this.pageno = pageNo;
}
public Integer getStartrow() {
return startrow;
}
/**
* 计算起始行
* @param pageNo
* @param pageSize
*/
public void setStartrow(Integer pageNo,Integer pageSize) {
this.startrow = (pageNo-1)*pageSize;
}
public Integer getTotalpage() {
return totalpage;
}
/**
* 计算总页数
* @param totalCount
* @param pageSize
*/
public void setTotalpage(Integer totalCount,Integer pageSize) {
this.totalpage = totalCount%pageSize==0?totalCount/pageSize:totalCount/pageSize+1;
}
public Integer getTotalcount() {
return totalcount;
}
public void setTotalCount(Integer totalCount) {
this.totalcount = totalCount;
}
@Override
public String toString() {
return "[{\"pageno\":" + pageno + ",\"pagesize\":" + pagesize
+ ",\"startrow\":" + startrow + ",\"totalcount\":" + totalcount
+ ",\"totalpage\":" + totalpage + "}]";
} }

Page.java

1.7 在项目的src下的com.util包下创建Hibernate_Util.java

 package com.util;

 import org.hibernate.HibernateException;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.cfg.Configuration; /**
* Hibernate打开session和关闭session
* @author Holly
*
*/
public class Hibernate_Util {
private static ThreadLocal<Session> threadLocal=new ThreadLocal<Session>();
private static Configuration configuration=null;
private static SessionFactory sessionFactory=null;
static{ try {
configuration=new Configuration().configure("/hibernate.cfg.xml");
sessionFactory=configuration.buildSessionFactory();
} catch (HibernateException e) {
System.out.println("解析xml和创建Session工厂error");
e.printStackTrace();
} } public static Session getSession(){
Session session=threadLocal.get();
if(session==null){
session=sessionFactory.openSession();
threadLocal.set(session);
}
return session;
}
public static void closeSession(){
Session session=threadLocal.get();
if(session!=null){
threadLocal.set(null);
session.close();
}
} }

Hibernate_Util.java

1.8 在项目的src下的com.dao包下创建StudentDao.java

 package com.dao;

 import java.util.Iterator;
import java.util.List; import org.hibernate.Hibernate;
import org.hibernate.Session; import com.entity.Student;
import com.page.Page;
import com.util.Hibernate_Util; import sun.print.resources.serviceui; public interface StudentDao {
/**
* 1.根据用户名和密码查询
* @param sname
* @param password
* @return
*/
Student findByNameAndPwd(String sname,String password);
/**
* 2.延时加载:查询所有
* @return
*/
List<Student> findAll();
/**
* 3.保存
* @param stu
* @return
*/
int save(Student stu);
/**
* 4.根据主键id查询单条
* @param sid
* @return
*/
Student findById(Integer sid);
/**
* 5.修改
*/
int update(Student stu);
/**
* 6.删除对象
* @param stu
* @return
*/
int delete(Student stu);
/**
* 7.分页查询
*/
List<Student> findPage(Page page);
/**
* 8.查询总条数
*/
int getTotalCount(); }

StudentDao.java

1.9 在项目的src下的com.dao.impl包下创建StudentDaoImpl.java

 package com.dao.impl;

 import java.util.List;

 import org.hibernate.HibernateException;
import org.hibernate.Query;
import org.hibernate.Session; import com.dao.StudentDao;
import com.entity.Student;
import com.page.Page;
import com.util.Hibernate_Util; public class StudentDaoImpl implements StudentDao{
/**
* 1.查询所有:立即加载
*/
public List<Student> findAll() {
//1.获取session对象
Session session=Hibernate_Util.getSession();
//2.定义hql语句
String hql="from Student";
//3.Session创建Query对象
Query query=session.createQuery(hql);
//4.query对象执行操作
List<Student> it=query.list();
//5.释放资源
Hibernate_Util.closeSession();
return it;
}
/**
* 2.根据用户名和密码查询
*/
public Student findByNameAndPwd(String sname, String password) {
//1.获取session对象
Session session=Hibernate_Util.getSession();
//2.定义hql语句(命名参数)
String hql="from Student where sname=:sname and password=:password";
//3.Session创建Query对象
Query query=session.createQuery(hql);
//4.query对象给占位符赋值
/*query.setString("sname", sname);
query.setString("password", password);*/
query.setParameter("sname", sname);
query.setParameter("password", password); // query.setProperties(user);
//5.执行操作(uniqueResult()查询的单行数据)
Student stu=(Student) query.uniqueResult();
//6.释放资源
Hibernate_Util.closeSession();
return stu; } /**
* 根据id主键查询单条
*/
public Student findById(Integer sid) {
//1.获取session对象
Session session=Hibernate_Util.getSession();
//2.利用session根据主键查询
Student stu=(Student) session.get(Student.class, sid);
/*3.
* 因为在修改时要提前查询单条,和session关联已经变成持久化对象,
* 而在修改时session执行update方法时,
* 首先会查询该主键id是否存在,
* 如果存在,则根据主键id修改该对象,此时对象已经处于持久化对象,
* 而实际session中不能同时存在两个主键id相同的对象,
* 否则会出现如下错误:
* org.hibernate.NonUniqueObjectException:
* a different object with the same identifier
* value was already associated with the
* session: [com.entity.Student#1]
*/
Hibernate_Util.closeSession();
// session.clear();
return stu;
}
/**
* 删除对象
*/
public int delete(Student stu) {
int num=1;
//1.获取session对象
Session session=Hibernate_Util.getSession(); try {
//session删除操作
session.delete(stu);
session.beginTransaction().commit();
} catch (HibernateException e) {
num=0;
// TODO Auto-generated catch block
e.printStackTrace();
}finally{
//5.释放资源
Hibernate_Util.closeSession();
} return num;
}
/**
* 添加
*/
public int save(Student stu) {
int num=1;
//1.获取session对象
Session session=Hibernate_Util.getSession();
//执行操作
try {
session.save(stu);
session.beginTransaction().commit();
} catch (HibernateException e) {
num=0;
e.printStackTrace();
}finally{
//5.释放资源
Hibernate_Util.closeSession();
}
return num;
}
/**
* 修改
*/
public int update(Student stu) {
int num=1;
//1.获取session对象
Session session=Hibernate_Util.getSession();
try {
//执行操作
//该对象的主键id必须存在
session.update(stu);
session.beginTransaction().commit();
} catch (HibernateException e) {
num=0;
e.printStackTrace();
}finally{
//5.释放资源
Hibernate_Util.closeSession();
}
return num;
}
/**
* 7.分页查询
*/
public List<Student> findPage(Page page) {
//1.获取session
Session session=Hibernate_Util.getSession(); //2.定义查询最大记录数的hql
String hql="from Student"; //3.定义查询最大记录数的Query对象
Query querypage=session.createQuery(hql); //4.查询最大记录数的数据
querypage.setMaxResults(page.getPagesize()); //5.确定查询起点
querypage.setFirstResult(page.getStartrow()); //6.分页查询
List<Student> list=querypage.list(); //7.关闭session
Hibernate_Util.closeSession(); return list;
}
/**
* 8.查询总条数
*/
public int getTotalCount() {
//1.获取session
Session session=Hibernate_Util.getSession(); //2.定义查询总条数hql语句
String hqlcount="select count(*) from Student"; //3.利用Session创建Query对象
Query querycount=session.createQuery(hqlcount); //4.获取总条数(返回单行数据uniqueResult())
Integer totalCount=Integer.parseInt(querycount.uniqueResult().toString());
//5.释放资源
Hibernate_Util.closeSession();
return totalCount;
} }

StudentDaoImpl.java

1.10 在项目的src下的com.service包下创建StudentService.java

 package com.service;

 import java.util.List;

 import com.entity.Student;
import com.page.Page; /**
* 业务接口
* @author pc
*
*/
public interface StudentService {
/**
* 1.登录的业务
* @param sname
* @param password
* @return
*/
Student login(String sname,String password);
/**
* 2.注册
* @param stu
* @return
*/
int register(Student stu); /**
* 3.查询所有
*/
List<Student> findAll();
/**
* 4.根据主键id查询
* @param sid
* @return
*/
Student findById(Integer sid);
/**
* 5.修改
*/
int update(Student stu);
/**
* 6.删除
*/
int delete(Student stu); /**
* 7.分页查询
*/
List<Student> findPage(Page page);
/**
* 8.查询总条数
*/
int getTotalCount(); }

StudentService.java

1.11 在项目的src下的com.service.impl包下创建StudentServiceImpl.java

 package com.service.impl;

 import java.util.Iterator;
import java.util.List; import com.dao.StudentDao;
import com.dao.impl.StudentDaoImpl;
import com.entity.Student;
import com.page.Page;
import com.service.StudentService; public class StudentServiceImpl implements StudentService {
/**
* 使用多态引用数据访问层对象
*/
private StudentDao dao = new StudentDaoImpl(); /**
* 登录
*/
public Student login(String sname, String password) {
return dao.findByNameAndPwd(sname, password);
} public int delete(Student stu) {
// TODO Auto-generated method stub
return dao.delete(stu);
} public List<Student> findAll() {
// TODO Auto-generated method stub
return dao.findAll();
} public Student findById(Integer sid) {
// TODO Auto-generated method stub
return dao.findById(sid);
} public int register(Student stu) {
// TODO Auto-generated method stub
return dao.save(stu);
} public int update(Student stu) {
// TODO Auto-generated method stub
return dao.update(stu);
} public List<Student> findPage(Page page) {
// TODO Auto-generated method stub
return dao.findPage(page);
} public int getTotalCount() {
// TODO Auto-generated method stub
return dao.getTotalCount();
} }

StudentServiceImpl.java

1.12 在项目的WebRoot下创建login.jsp页面

 <%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme() + "://"
+ request.getServerName() + ":" + request.getServerPort()
+ path + "/";
%> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<base href="<%=basePath%>"> <title>My JSP 'index.jsp' starting page</title>
<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="This is my page">
<!--
<link rel="stylesheet" type="text/css" href="styles.css">
-->
</head> <body>
<center>
<fieldset style="width: 300px;">
<legend>
登录
</legend>
<form action="LoginServlet" method="post">
<table>
<tr>
<td>
用户名:
</td>
<td>
<input type="text" name="sname" />
</td>
</tr>
<tr>
<td>
密码:
</td>
<td>
<input type="password" name="password" />
</td>
</tr>
<tr>
<td>
<input type="submit" value="提交" />
</td>
<td>
<input type="reset" value="重置" />
</td>
</tr>
</table>
</form>
</fieldset>
</center>
</body>
</html>

login.jsp

1. 13 在项目的src下的com.servlet包下创建LoginServlet.java

 package com.servlet;

 import java.io.IOException;
import java.io.PrintWriter; import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse; import com.entity.Student;
import com.service.StudentService;
import com.service.impl.StudentServiceImpl; public class LoginServlet extends HttpServlet { public void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException { this.doPost(request, response);
} public void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
request.setCharacterEncoding("UTF-8");
response.setCharacterEncoding("UTF-8");
response.setContentType("text/html;charset=UTF-8"); //2.接受参数
String sname=request.getParameter("sname");
String password=request.getParameter("password");
//3.业务处理
StudentService service=new StudentServiceImpl();
Student stu=service.login(sname, password);
if(stu!=null){
System.out.println("login success!");
//4.页面跳转
request.getSession().setAttribute("sname", sname);
response.sendRedirect("FindAllServlet");
}else{
System.out.println("login fail!"); } } }

LoginServlet.java

1.14 在项目WebRoot下的WEB-INF下的web.xml中配置servlet

 <?xml version="1.0" encoding="UTF-8"?>
<web-app version="2.5"
xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">
<servlet>
<servlet-name>LoginServlet</servlet-name>
<servlet-class>com.servlet.LoginServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>LoginServlet</servlet-name>
<url-pattern>/LoginServlet</url-pattern>
</servlet-mapping>
<welcome-file-list>
<welcome-file>login.jsp</welcome-file>
</welcome-file-list>
</web-app>

web.xml

1.15 在项目的src下的com.servlet包下创建FindAllServlet.java

 package com.servlet;

 import java.io.IOException;
import java.io.PrintWriter;
import java.util.Iterator;
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.entity.Student;
import com.page.Page;
import com.service.StudentService;
import com.service.impl.StudentServiceImpl; public class FindAllServlet extends HttpServlet { public void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException { this.doPost(request, response);
} public void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
request.setCharacterEncoding("UTF-8");
response.setCharacterEncoding("UTF-8");
response.setContentType("text/html;charset=UTF-8"); /**
* ☆
* 在使用ajax往前台通过输出流对象的print方法发送json时
* 该行获取输出流对象的代码必须放在
* response.setContentType("text/html;charset=UTF-8");
* 之后,否则ajax回调时,页面拿到的中文数据就永远都是乱码,
* 原因是:如果将改行代码写在处理客户端乱码之前,表示编码格式已经确定,
* 所以,编码格式的处理应该放在获取PrintWriter对象之前
*
*/
PrintWriter out=response.getWriter(); // 2.接受参数
String no=request.getParameter("pageNo"); // 3.业务处理
StudentService service = new StudentServiceImpl(); int pageSize=3; //页面大小
int pageNo=1; //默认的pageNo为1
if(no!=null && no!=""){
pageNo=Integer.valueOf(no);
}
//获取总条数
int totalCount=service.getTotalCount();
Page page=new Page(pageSize, pageNo, totalCount); List<Student> list = service.findPage(page);
if(list!=null){
System.out.println("find All page success");
request.setAttribute("list", list);
request.setAttribute("page", page);
request.getRequestDispatcher("index.jsp").forward(request, response);
}else{
System.out.println("find All page fail!"); } } }

FindAllServlet.java

1.16. 在项目的WebRoot下创建index.jsp页面

 <%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme() + "://"
+ request.getServerName() + ":" + request.getServerPort()
+ path + "/";
%> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<base href="<%=basePath%>"> <title>My JSP 'index.jsp' starting page</title>
<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="This is my page">
<!--
<link rel="stylesheet" type="text/css" href="styles.css">
-->
</head> <body>
<CENTER>
<table>
<tr>
<td colspan="4">
<a href="register.jsp">注册</a>
</td>
</tr>
<tr>
<td>
序号
</td>
<td>
姓名
</td>
<td>
性别
</td>
<td>
操作
</td>
</tr> <c:forEach var="i" items="${list}">
<tr>
<td>
${i.sid }
</td>
<td>
${i.sname }
</td>
<td>
${i.sex }
</td>
<td>
<a href="FindByIdSerlvet?sid=${i.sid}">修改</a>
&nbsp;&nbsp;
<a href="DeleteSerlvet?sid=${i.sid}">删除</a> </td>
</tr>
</c:forEach> </table>
<div> 第${page.pageno}/${page.totalpage}页 &nbsp;&nbsp;
<a href="FindAllServlet?pageNo=1">首页</a>
<c:choose>
<c:when test="${page.pageno gt 1}">
<a href="FindAllServlet?pageNo=${page.pageno-1 }">上一页</a>
</c:when>
<c:otherwise>
<a href="javascript:alert('已经是第一页了,没有上一页!');">上一页</a>
</c:otherwise>
</c:choose>
<c:choose>
<c:when test="${page.pageno lt page.totalpage}">
<a href="FindAllServlet?pageNo=${page.pageno+1 }">下一页</a>
</c:when>
<c:otherwise>
<a href="javascript:alert('已经是最有一页了,没有下一页!');">下一页</a>
</c:otherwise>
</c:choose> <a href="FindAllServlet?pageNo=${page.totalpage}">末页</a>
&nbsp;&nbsp;
共${page.totalcount}条 </div> </CENTER> </body>
</html>

index.jsp

1.17 运行登录和查询的效果

1.18 在项目的WebRoot下创建register.jsp页面

 <%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%
String path = request.getContextPath();
String basePath = request.getScheme() + "://"
+ request.getServerName() + ":" + request.getServerPort()
+ path + "/";
%> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<base href="<%=basePath%>"> <title>My JSP 'index.jsp' starting page</title>
<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="This is my page">
<!--
<link rel="stylesheet" type="text/css" href="styles.css">
-->
</head> <body>
<center>
<fieldset style="width: 300px;">
<legend>
注册
</legend>
<form action="RegisterServlet" method="post">
<table>
<tr>
<td>
用户名:
</td>
<td>
<input type="text" name="sname"/>
</td>
</tr>
<tr>
<td>
密码:
</td>
<td>
<input type="password" name="password"/>
</td>
</tr>
<tr>
<td>
性别:
</td>
<td>
<input type="radio" name="sex" value="男" checked="checked"/>男
<input type="radio" name="sex" value="女"/>女
</td>
</tr>
<tr>
<td>
班级编号:
</td>
<td>
<select name="cid">
<option value="1">TB07</option>
<option value="2">TB13</option>
<option value="3">TB24</option>
<option value="4">TB31</option>
</select>
</td>
</tr>
<tr>
<td>
<input type="submit" value="修改" />
</td>
<td>
<input type="reset" value="重置" />
</td>
</tr>
</table>
</form>
</fieldset>
</center>
</body>
</html>

register.jsp

1.19.在项目的src下的com.servlet包下创建RegisterServlet.java

 package com.servlet;

 import java.io.IOException;
import java.io.PrintWriter; import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse; import com.entity.Student;
import com.service.StudentService;
import com.service.impl.StudentServiceImpl; public class RegisterServlet extends HttpServlet {
public void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException { this.doPost(request, response);
} public void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
request.setCharacterEncoding("UTF-8");
response.setCharacterEncoding("UTF-8");
response.setContentType("text/html;charset=UTF-8"); // 2.接受参数
String sname = request.getParameter("sname");
String password = request.getParameter("password");
String sex = request.getParameter("sex");
Integer cid = Integer.valueOf(request.getParameter("cid"));
Student stu = new Student(sname, password, sex, cid); // 3.业务处理
StudentService service = new StudentServiceImpl();
int num = service.register(stu);
if (num > 0) {
System.out.println("register success!");
response.sendRedirect("FindAllServlet");
} else {
System.out.println("register fail!"); } } }

RegisterServlet.java

1.20 在上面点击注册超链接出现如下页面

1.21  在项目的WebRoot下创建update.jsp页面

 <%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%
String path = request.getContextPath();
String basePath = request.getScheme() + "://"
+ request.getServerName() + ":" + request.getServerPort()
+ path + "/";
%> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<base href="<%=basePath%>">
<title>My JSP 'index.jsp' starting page</title>
<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="This is my page">
<!--
<link rel="stylesheet" type="text/css" href="styles.css">
-->
</head> <body>
<center>
<fieldset style="width: 300px;">
<legend>
<br>修改
</legend>
<form action="UpdateServlet?sid=${stu.sid}" method="post">
<table>
<tr>
<td>
用户名:
</td>
<td>
<input type="text" name="sname" value="${stu.sname}"/>
</td>
</tr>
<tr>
<td>
密码:
</td>
<td>
<input type="password" name="password" value="${stu.password}"/>
</td>
</tr>
<tr>
<td>
性别:
</td>
<td>
<c:choose>
<c:when test="${stu.sex eq '男'}">
<input type="radio" name="sex" value="男" checked="checked"/>男
<input type="radio" name="sex" value="女"/>女
</c:when>
<c:otherwise>
<input type="radio" name="sex" value="男"/>男
<input type="radio" name="sex" value="女" checked="checked"/>女
</c:otherwise>
</c:choose>
</td>
</tr>
<tr>
<td>
班级编号:
</td>
<td>
<select name="cid">
<option value="1">TB07</option>
<option value="2">TB13</option>
<option value="3">TB24</option>
<option value="4">TB31</option>
</select>
</td>
</tr> <tr>
<td>
<input type="submit" value="修改" />
</td>
<td>
<input type="reset" value="重置" />
</td>
</tr>
</table>
</form>
</fieldset>
</center>
</body>
</html>

update.jsp

1.22  在项目的src下的com.servlet包下创建FindByIdSerlvet.java

 package com.servlet;

 import java.io.IOException;
import java.io.PrintWriter; import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse; import com.entity.Student;
import com.service.StudentService;
import com.service.impl.StudentServiceImpl;
import com.util.Hibernate_Util; public class FindByIdSerlvet extends HttpServlet {
public void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException { this.doPost(request, response);
} public void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
request.setCharacterEncoding("UTF-8");
response.setCharacterEncoding("UTF-8");
response.setContentType("text/html;charset=UTF-8"); // 2.接受参数
Integer sid=Integer.valueOf(request.getParameter("sid")); // 3.业务处理
StudentService service = new StudentServiceImpl(); Student stu=service.findById(sid);
System.out.println("stu:"+stu);
if(stu!=null){
System.out.println("根据id查询到对象");
request.setAttribute("stu", stu);
request.getRequestDispatcher("update.jsp").forward(request, response);
}else{
System.out.println("没有根据id查询到对象");
} } } FindByIdSerlvet.java

FindByIdServlet.java

1.23  在项目的src下的com.servlet包下创建UpdateServlet.java

 package com.servlet;

 import java.io.IOException;
import java.io.PrintWriter; import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse; import com.entity.Student;
import com.service.StudentService;
import com.service.impl.StudentServiceImpl; public class UpdateServlet extends HttpServlet {
public void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException { this.doPost(request, response);
} public void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
request.setCharacterEncoding("UTF-8");
response.setCharacterEncoding("UTF-8");
response.setContentType("text/html;charset=UTF-8"); // 2.接受参数
Integer sid=Integer.valueOf(request.getParameter("sid"));
String sname = request.getParameter("sname");
String password = request.getParameter("password");
String sex = request.getParameter("sex");
Integer cid=Integer.valueOf(request.getParameter("cid"));
Student stu=new Student(sid,sname, password, sex, cid); // 3.业务处理
StudentService service = new StudentServiceImpl();
int num=service.update(stu);
if(num>0){
System.out.println("update success!");
response.sendRedirect("FindAllServlet");
}else{
System.out.println("update fail!"); } } }

UpdateServlet.java

1.24  点击修改超链接,进行修改会出现如下页面

1. 25 在项目的src下的com.servlet包下创建DeleteSerlvet.java

 package com.servlet;

 import java.io.IOException;
import java.io.PrintWriter; import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse; import com.entity.Student;
import com.service.StudentService;
import com.service.impl.StudentServiceImpl; public class DeleteSerlvet extends HttpServlet {
public void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException { this.doPost(request, response);
} public void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
request.setCharacterEncoding("UTF-8");
response.setCharacterEncoding("UTF-8");
response.setContentType("text/html;charset=UTF-8"); // 2.接受参数
Integer sid=Integer.valueOf(request.getParameter("sid"));
// 3.业务处理
StudentService service = new StudentServiceImpl();
Student stu=service.findById(sid);
if (stu != null) {
System.out.println("根据id查询成功");
int num=service.delete(stu);
if(num>0){
System.out.println("delete success!!");
// 4.页面跳转
response.sendRedirect("FindAllServlet"); }else{
System.out.println("delete success!!"); }
} else {
System.out.println("根据id查询失败!"); } } }

DeleteSerlvet.java

1.26 点击第一条删除

1.26 在项目的src下的com.servlet包下创建FindPageServlet.java

 package com.servlet;

 import java.io.IOException;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.Hashtable;
import java.util.List; import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse; import org.codehaus.jackson.map.ObjectMapper; import com.entity.Student;
import com.page.Page;
import com.service.StudentService;
import com.service.impl.StudentServiceImpl; /**
* 分页查询
*
* @author pc
*
*/
public class FindPageServlet extends HttpServlet { public void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException { this.doPost(request, response);
} public void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
response.setContentType("text/html;charset=UTF-8");
request.setCharacterEncoding("UTF-8");
response.setCharacterEncoding("UTF-8");
/**
* ☆
* 在使用ajax往前台通过输出流对象的print方法发送json时
* 该行获取输出流对象的代码必须放在
* response.setContentType("text/html;charset=UTF-8");
* 之后,否则ajax回调时,页面拿到的中文数据就永远都是乱码,
* 原因是:如果将改行代码写在处理客户端乱码之前,表示编码格式已经确定,
* 所以,编码格式的处理应该放在获取PrintWriter对象之前
*
*/
PrintWriter out=response.getWriter(); // 2.接受参数
String no=request.getParameter("pageNo"); // 3.业务处理
StudentService service = new StudentServiceImpl(); int pageSize=3; //页面大小
int pageNo=1; //默认的pageNo为1
if(no!=null && no!=""){
pageNo=Integer.valueOf(no);
}
//获取总条数
int totalCount=service.getTotalCount();
//封装分页所需字段
Page page=new Page(pageSize, pageNo, totalCount);
//分页查询
List<Student> list = service.findPage(page); ObjectMapper om=new ObjectMapper();
String str=om.writeValueAsString(list);
String pagestr=om.writeValueAsString(page);
str="{\"page\":"+pagestr+",\"list\":"+str+"}";
System.out.println(str); out.print(str);
/*if (list != null) {
System.out.println("find page success");
request.setAttribute("list", list);
request.setAttribute("page", page);
request.getRequestDispatcher("index.jsp").forward(request, response);
} else {
System.out.println("find page fail!"); }*/ } }

FindPageServlet.java

1. 27 在项目WebRoot下创建ajaxindex.jsp

 <%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme() + "://"
+ request.getServerName() + ":" + request.getServerPort()
+ path + "/";
%> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<base href="<%=basePath%>"> <title>My JSP 'index.jsp' starting page</title>
<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="This is my page">
<!--
<link rel="stylesheet" type="text/css" href="styles.css">
-->
<script type="text/javascript" src="js/jquery-1.8.3.js"></script>
<script type="text/javascript" src="js/ajaxindex.js"></script>
</head> <body>
<CENTER> <table></table>
<div>
第<span id="pageNo"></span>/<span id="totalPage"></span>页 &nbsp;&nbsp;
<a href="javascript:void(0);" class="apage">首页</a> &nbsp;&nbsp;
<a href="javascript:void(0);" class="apage">上一页</a> &nbsp;&nbsp;
<a href="javascript:void(0);" class="apage">下一页</a> &nbsp;&nbsp;
<a href="javascript:void(0);" class="apage">末页</a>&nbsp;&nbsp;
共<span id="totalCount"></span>条
</div> </CENTER> </body>
</html>

ajaxindex.jsp

1.28 在项目WebRoot下的WEB-INF下的web.xml中配置servlet

 <?xml version="1.0" encoding="UTF-8"?>
<web-app version="2.5"
xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">
<servlet>
<servlet-name>LoginServlet</servlet-name>
<servlet-class>com.servlet.LoginServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>LoginServlet</servlet-name>
<url-pattern>/LoginServlet</url-pattern>
</servlet-mapping>
<servlet>
<servlet-name>FindAllServlet</servlet-name>
<servlet-class>com.servlet.FindAllServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>FindAllServlet</servlet-name>
<url-pattern>/FindAllServlet</url-pattern>
</servlet-mapping>
<servlet>
<servlet-name>RegisterServlet</servlet-name>
<servlet-class>com.servlet.RegisterServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>RegisterServlet</servlet-name>
<url-pattern>/RegisterServlet</url-pattern>
</servlet-mapping> <servlet>
<servlet-name>FindByIdSerlvet</servlet-name>
<servlet-class>com.servlet.FindByIdSerlvet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>FindByIdSerlvet</servlet-name>
<url-pattern>/FindByIdSerlvet</url-pattern>
</servlet-mapping> <servlet>
<servlet-name>UpdateServlet</servlet-name>
<servlet-class>com.servlet.UpdateServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>UpdateServlet</servlet-name>
<url-pattern>/UpdateServlet</url-pattern>
</servlet-mapping>
<servlet>
<servlet-name>DeleteSerlvet</servlet-name>
<servlet-class>com.servlet.DeleteSerlvet</servlet-class>
</servlet> <servlet-mapping>
<servlet-name>DeleteSerlvet</servlet-name>
<url-pattern>/DeleteSerlvet</url-pattern>
</servlet-mapping>
<servlet>
<servlet-name>FindPageServlet</servlet-name>
<servlet-class>com.servlet.FindPageServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>FindPageServlet</servlet-name>
<url-pattern>/FindPageServlet</url-pattern>
</servlet-mapping> <welcome-file-list>
<welcome-file>login.jsp</welcome-file>
</welcome-file-list>
</web-app>

web.xml

1.29 在项目WebRoot下的js文件中创建ajaxindex.js

 $(function() {
/*1.获取页面上span标签中显示的pageNo的值
* 因为第一次span标签里没有,所以为空,
* 此时后台因为前台接到的是空,后台就会默认给1,
* 然后再返回前台页面,
* 所以第一次使用ajax回调时pageNo传过去为null,
* 第二次是页面点击分页超链接重新赋值pageNo
* 所以这里ajax第一次访问和点击分页查询可以提取成一个方法
*/
var pageNo = $("#pageNo").text(); /*
* 2.ajax第一次通过页面去后台服务器回调数据
* 调用ajax公共函数实现回调(第一次访问参数是null,
* 等第一次访问从后代服务器回来时,将会带一个pageNo的值回来,
* 然后将该值放入分页的span标签id为pageNo中,
* 所以第二次访问的pageNo就有值了,该值是上一次访问从后台带回来的值
*/
getAjaxPage(pageNo); /*
* 3.超链接分页查询
* ajax非第一次去后台获取数据
*/
$(".apage").click(function() {
/*
* 3.1获取pageNo的值
* 获取的是上一次回调过后放在id为pageNo的span标签的值
*/
var pageNo = parseInt($("#pageNo").text());
/*
* 3.2 获取totalPage的值
* 获取的是上一次回调过后放在id为totalPage的span标签的值
*/
var totalPage = parseInt($("#totalPage").text()); /*
* 3.3获取分页超链接的文本
* 因为要判断是首页?上一页?下一页?末页?
* 从而重新给pageNo设值
*/
var pagetext = $(this).html();
//去 alert(pagetext); /*
* 4.判断是首页?上一页?下一页?末页?
* 从而重新给pageNo设值
* */
if (pagetext == "首页") {
pageNo = 1;
} else if (pagetext == "上一页") {
if (pageNo > 1) {
pageNo = pageNo - 1;
} else {
alert("已经是第一页了!");
//如果已经是第一页了,则不容许接下来的操作再进行所以return
return;
}
} else if (pagetext == "下一页") {
if (pageNo < totalPage) {
pageNo = pageNo + 1;
} else {
alert("已经是最后一页了!");
//如果已经是最后一页了,则不容许接下来的操作再进行所以return
return;
}
} else if (pagetext == "末页") {
pageNo = totalPage;
} //去 alert("pageNo:"+pageNo);
/*
* 5.调用ajax公共函数实现回调
* 注意:此时调用时非第一次调用,而且pageNo是肯定有值的
*/
getAjaxPage(pageNo); }); }); /*二. ajax异步分页公共函数*/
function getAjaxPage(pageNo) {
/**
* url:要回调的地址
* type:是请求的方式,post或get
* dataType:是回调函数得到的数据类型
* data:表示的发到后台的的参数,
* 后台回去的时候是通过request.getParameter("key")获取
* 参数名建议用双引号引起来
* contenttype:设置页面发送到后台服务器的文字进行乱码处理
* async:ajax异步属性,默认值为true表示异步,为false表示同步
* success:表示数据成功回调后处理的函数,obj是承载后台数据的参数默认是Object类型
* error:表示数据回调失败的处理的函数,
*
*/
$.ajax( {
url:'FindPageServlet',
type:'post',
dataType:'json',
data:{"pageNo":pageNo},
async:true,
contenttype:"application/x-www-form-urlencoded;charset=UTF-8",
success:function(obj) {
/*
* 2.1 由于每一次回调的数据不一样,但却是放在同一个table标签中
* 所以在每次添加新数据之前,要将上一次内容清空,再添加新的
*/
$("table").html(" "); /*
* 2.2 获取后台回来的pageNo的值,
* 并添加到页面id为pageNo的span标签中,
* 以备下一次点击分页超链接时使用*/
//var pageNo = obj.page[0].pageno;
var pageNo = obj.page.pageno;
$("#pageNo").text(pageNo); /*
* 2.3 获取后台回来的totalPage的值,
* 并添加到页面id为totalPage的span标签中,
* 以备下一次点击分页超链接时使用*/
//var totalPage = obj.page[0].totalpage;
var totalPage = obj.page.totalpage;
$("#totalPage").text(totalPage); /*
* 2.4 获取后台回来的totalCount的值,
* 并添加到页面id为totalCount的span标签中,
* 以备下一次点击分页超链接时使用*/
//var totalCount = obj.page[0].totalcount;
var totalCount = obj.page.totalcount;
$("#totalCount").text(totalCount); /*
* 2.5 拼接table行数据*/
str = "<tr><td><a href='register.jsp'>注册</a><td></tr>";
str += "<tr><td>序号</td><td>姓名</td><td>性别</td><td>操作</td></tr>"; /*2.6
* 循环后台回调的list对象数组中的数据,
* 并将数据取出拼接成tr行进行显示
* */
$.each(obj.list, function(i) {
str += "<tr><td>" + obj.list[i].sid + "</td><td>"
+ obj.list[i].sname + "</td><td>" + obj.list[i].sex
+ "</td><td><a href='FindByIdSerlvet?sid="+obj.list[i].sid+"'>修改</a>&nbsp;&nbsp;<a href=''>删除</a></td></tr>";
}); /*2.7 将拼接好的数据行放入table中*/
$("table").append(str);
},
error : function() {
alert("error");
}
});
}

ajaxindex.js

1.30 运行页面

5.Hibernate实现全套增删改查和ajax异步分页的更多相关文章

  1. MyBatis简单的增删改查以及简单的分页查询实现

    MyBatis简单的增删改查以及简单的分页查询实现 <? xml version="1.0" encoding="UTF-8"? > <!DO ...

  2. Hibernate全套增删改查+分页

    1.创建一个web工程 2.导入jar包 3.创建Student表 4.创建实体类 package com.entity; public class Student { private Integer ...

  3. 肝 hibernate 配置and增删改查 and 测试

    已经通宵三天撸代码了,现在的我已经养成晚上修仙写代码的节奏了.....最近 刚刚复习到了 hibernate 谈谈 这篇文章就谈谈我对这货的理解吧. 在看这篇文章之前希望你 知道sessionfact ...

  4. Hibernate下的增删改查

    概述: 关系--对象映射的中间件,属于开源ORM框架,是我们业务逻辑层中的调用数据库的中间件 演变: jdbc---hibernater---mybatis hibernate和mybatis区别? ...

  5. Hibernate入门_增删改查

    一.Hibernate入门案例剖析:  ①创建实体类Student 并重写toString方法 public class Student { private Integer sid; private ...

  6. hibernate搭建及其增删改查

    一.jar包 最基础的hibernatejar包,以及数据库驱动的jar包 二.数据库 t_user表 id int 主键 自动增长 name varchar() 三.配置文件 <?xml ve ...

  7. hibernate的配置, 增删改查

    路径:查找路径 实际上都是查找编译后的对应的路径,在bin文件夹中总 增删改必须开启事务才行 hibernate加载文件的两种方式 configure 1.引包 antlr-2.7.6.jar bac ...

  8. 14.hibernate的反向生成实现全套增删改查

    图片顺序就是步骤顺序 1. 2. 3. 4. 5. 6. 7. 8. 9. 10. 11. 12. 13. 14. 15. 16. 17. 18.

  9. struts+hibernate 请求数据库增删改查(小项目实例)

      StudentAction.java package com.action; import java.util.ArrayList; import java.util.List; import j ...

随机推荐

  1. 上传代码到GitHub时,遇到错误:fatal,The Requested URL return error 403

    解决: from:pushing-to-git-returning-error-code-403-fatal-http-request-failed

  2. 利用python3.5 构建流媒体后台音视频切换的服务端程序

    #!/usr/bin/env python3.5.0 # -*- coding:utf8 -*- import os,sys,socket,hashlib,time,select,threading, ...

  3. 【转】判断URL是否能够访问

    import urllib2 def file_exists(url): request = urllib2.Request(url) request.get_method = lambda : 'H ...

  4. C语言温度

    #include <stdio.h> #include <stdlib.h> /* run this program using the console pauser or a ...

  5. 【bootstrap】时间选择器datetimepicker和daterangepicker

    在bootstrap中的时间选择器有两种:dateTimePicker和dateRangePicker 1.dateTimePicker好像是官方嫡插件:   需要的文件: <link rel= ...

  6. Java的“影子克隆”和“深度克隆”

    今天来学习学习java对象的克隆,在写代码的时候,有时候我们会这样写:对象1=对象2,也就是把对象2赋值给对象1了,但是这样做有个问题,就是如果我们修改了对象2的属性值,对象1的相同属性值也被修改了, ...

  7. 洛谷-谁拿了最多奖学金-NOIP2005提高组复赛

    题目描述 Description 某校的惯例是在每学期的期末考试之后发放奖学金.发放的奖学金共有五种,获取的条件各自不同: 1)     院士奖学金,每人8000元,期末平均成绩高于80分(>8 ...

  8. As input tri-stated

    前些日子正好看到了riple兄的<一波三折--危险的"未分配"引脚>一文,颇受启发.正好最近也遇上了类似的问题,也可谓一波三折,还好最后摆平了,要不煮熟的鸭子可就要飞了 ...

  9. Java集合初体验

    背景:        因为对Java的集合完全不了解,所以才在网上找了找能形成初步印象的文章进行学习,大多涉及的是一些概念和基础知识. 一.数组array和集合的区别: (1)数组是大小固定的,并且同 ...

  10. qemu毒液漏洞分析(2015.9)

    0x00背景 安全娱乐圈媒体Freebuf对该漏洞的有关报道: 提供的POC没有触发崩溃,在MJ0011的博客给出了修改后可以使qemu崩溃的poc.详见: http://blogs.360.cn/b ...