源码下载地址:
http://download.csdn.net/detail/diudiu666hf/9667695
上面这个错误是我引入了一个动画jquery-2.1.4.min.js引入可能有问题但是不耽误程序,动画还能动就没有管它
先说基本的操作数据库的连接在util包下创建了DBO类
package cn.edu.hpu.util;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
public class DBO {
static String url="jdbc:mysql://localhost:3306/dl";
static String user="root";
static String password="123";
static{
try {
Class.forName("com.mysql.jdbc.Driver");
} catch (ClassNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
public static Connection getConnection() {
Connection conn=null;
try {
conn=DriverManager.getConnection(url, user, password);
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return conn;
}
public static void close(Statement st,ResultSet rs,Connection conn) {
try {
if(st!=null) {
st.close();
}
if(rs!=null) {
rs.close();
}
if(conn!=null) {
conn.close();
}
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
public static void close(PreparedStatement pst,Connection conn) {
try {
if(pst!=null) {
pst.close();
}
if(conn!=null) {
conn.close();
}
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
以及验证码的servlet
package cn.edu.hpu.servlet;
import java.awt.Color;
import java.awt.Font;
import java.awt.Graphics;
import java.awt.image.BufferedImage;
import java.io.IOException;
import java.util.Random;
import javax.imageio.ImageIO;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
public class PicCodeGenerator extends HttpServlet {
public void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
doPost(request, response);
}
public void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
request.setCharacterEncoding("utf-8");
response.setCharacterEncoding("utf-8");
BufferedImage bi=new BufferedImage(68,22,BufferedImage.TYPE_INT_BGR);
Graphics g=bi.getGraphics();
Color color=new Color(224,205,19);
g.setColor(color);
g.fillRect(0, 0, 68,22);
char [] c="abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789".toCharArray();
Random random= new Random();
int len=c.length;
int temp;
StringBuffer sb=new StringBuffer(4);
for(int i = 0 ; i<4 ; i++){
char index = c[(int)(0+Math.random()*c.length)];
Font font = new Font("幼圆",Font.BOLD,25);
Color clo = new Color(random.nextInt(255));
g.setFont(font);
g.setColor(clo);
g.drawString(index+"",i*15,18);
g.setColor(new Color(random.nextInt(150),random.nextInt(220),random.nextInt(180)));
sb.append(index);
}
for(int i=0;i<5;i++) {
g.drawLine(random.nextInt(68),random.nextInt(22),random.nextInt(68), random.nextInt(22));
}
request.getSession().setAttribute("piccode", sb.toString());
ImageIO.write(bi, "JPG", response.getOutputStream());
}
}
以及分页的一些类
package cn.edu.hpu.dao;
import java.util.List;
public class PageBean {
private int pc;
private int ps;
private int tr;
private String url;
private List beanlist;
public int getTp() {
int tp=tr/ps;
return tr%ps==0?tp:tp+1;
}
public int getPc() {
return pc;
}
public void setPc(int pc) {
this.pc = pc;
}
public int getPs() {
return ps;
}
public void setPs(int ps) {
this.ps = ps;
}
public int getTr() {
return tr;
}
public void setTr(int tr) {
this.tr = tr;
}
public String getUrl() {
return url;
}
public void setUrl(String url) {
this.url = url;
}
public List getBeanlist() {
return beanlist;
}
public void setBeanlist(List beanlist) {
this.beanlist = beanlist;
}
}
package cn.edu.hpu.dao;
import cn.edu.hpu.domain.Student;
public interface StudentDao {
//分页的实现
public PageBean findByPageBean(int pc);
}
package cn.edu.hpu.daoimpl;
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.ArrayList;
import java.util.List;
import cn.edu.hpu.dao.PageBean;
import cn.edu.hpu.dao.StudentDao;
import cn.edu.hpu.domain.Student;
import cn.edu.hpu.util.DBO;
public class StudentDaoImpl implements StudentDao {
@Override
public PageBean findByPageBean(int pc) {
Connection conn = null;
Statement st = null;
ResultSet rs = null;
/**
* 1. ps
*/
int ps =10;
try {
conn = DBO.getConnection();
st = (Statement) conn.createStatement();
/**
* 2.tr 通过查询数据库
*/
int tr = 0;
String sql = "SELECT COUNT(*) FROM student";
rs = st.executeQuery(sql);
while(rs.next()){
tr = rs.getInt("count(*)");//count并不是数据库里的列名,默认为列名
//rs.getInt(1);
}
/**
* 3. 数据集合
* SELECT * FROM t_user LIMIT 0,3
*
* 1 : 当前页第一条记录的下标 begin (pc-1)*ps
* 2 : 每页查询的记录数 ps
*/
List list = new ArrayList();
int begin = (pc-1)*ps;
sql = "SELECT * FROM student LIMIT "+ begin +","+ps;
rs = st.executeQuery(sql);
//遍历结果集
while(rs.next()){
Student student = new Student();
student.setId(rs.getInt("id"));
student.setName(rs.getString("name"));
student.setPassword(rs.getString("password"));
student.setAddress(rs.getString("address"));
student.setBirthday(rs.getString("birthday"));
student.setGender(rs.getString("gender"));
student.setSid(rs.getString("sid"));
//将遍历产生的对象,添加到数据集合中
list.add(student);
}
//生成PageBean对象
PageBean pageBean = new PageBean();
pageBean.setPc(pc);
pageBean.setPs(ps);
pageBean.setTr(tr);
pageBean.setBeanlist(list);
return pageBean;
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return null;
}
}
package cn.edu.hpu.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 cn.edu.hpu.dao.PageBean;
import cn.edu.hpu.domain.Student;
import cn.edu.hpu.service.StudentService;
public class StudentServlet extends HttpServlet {
public void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
doPost(request, response);
}
public void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
StudentService studentService = new StudentService();
//获取请求路径
//http://localhost:8080/PageBeanDemon/StudentServlet?null&pc=6
//http://localhost:8080/PageBeanDemon/
//${pageContext.request.contextPath }/StudentServlet?null&pc=${pb.pc -1}
String uri = request.getRequestURI()+"?"+request.getQueryString();
int index=uri.indexOf("StudentServlet");
if(index==-1) {
uri="http://localhost:8080/student/StudentServlet?null";
}
index = uri.lastIndexOf("&pc=");
if(index != -1 ){
uri = uri.substring(0,index);
}
//获取当前页页码
int pc = 1;
String param = request.getParameter("pc");
if(param != null && !param.trim().isEmpty()){
//将string类型强制转化为Int类型
pc = Integer.parseInt(param);
}
PageBean pageBean = studentService.findByPageBean(pc);
//pageBean.setPc(pc);
pageBean.setUrl(uri);
/*
List list = pageBean.getBeanlist();
1.
for(int i=0; i
//将数据放到Request域
request.setAttribute("pb", pageBean);
//转发
request.getRequestDispatcher("Partner.jsp").forward(request, response);
}
}
由于学生查询时不能看到其他学生的密码,所以在创建一个servelt
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 cn.edu.hpu.dao.PageBean;
import cn.edu.hpu.domain.Student;
import cn.edu.hpu.service.StudentService;
public class StudentServlet1 extends HttpServlet {
public void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
doPost(request, response);
}
public void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
StudentService studentService = new StudentService();
//获取请求路径
//http://localhost:8080/PageBeanDemon/StudentServlet?null&pc=6
//http://localhost:8080/PageBeanDemon/
//${pageContext.request.contextPath }/StudentServlet?null&pc=${pb.pc -1}
String uri = request.getRequestURI()+"?"+request.getQueryString();
int index=uri.indexOf("StudentServlet");
if(index==-1) {
uri="http://localhost:8080/student/StudentServlet?null";
}
index = uri.lastIndexOf("&pc=");
if(index != -1 ){
uri = uri.substring(0,index);
}
//获取当前页页码
int pc = 1;
String param = request.getParameter("pc");
if(param != null && !param.trim().isEmpty()){
//将string类型强制转化为Int类型
pc = Integer.parseInt(param);
}
PageBean pageBean = studentService.findByPageBean(pc);
//pageBean.setPc(pc);
pageBean.setUrl(uri);
/*
List list = pageBean.getBeanlist();
1.
for(int i=0; i
//将数据放到Request域
request.setAttribute("pb", pageBean);
//转发
request.getRequestDispatcher("s.jsp").forward(request, response);
}
}
我的学生管理系统分为两个部分老师和学生 先说老师吧
一 老师可以对学生进行增删改查和查看学生的所有信息
1创建一个老师类 不需要太多变量用户名密码即可以及相应的get set方法
package cn.edu.hpu.domain;
public class Teacher {
private int id;
private String username;
private String password;
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public String getUsername() {
return username;
}
public void setUsername(String username) {
this.username = username;
}
public String getPassword() {
return password;
}
public void setPassword(String password) {
this.password = password;
}
}
2.这里写老师的登录注册的接口
package cn.edu.hpu.dao;
import cn.edu.hpu.domain.Teacher;
public interface TeacherManager {
public Teacher CheckLoding(String name,String password);
public boolean Register(Teacher teacher);
}
以及接口的实现类
package cn.edu.hpu.daoimpl;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import cn.edu.hpu.dao.TeacherManager;
import cn.edu.hpu.domain.Teacher;
import cn.edu.hpu.util.DBO;
public class TeacherManagerImpl implements TeacherManager {
@Override
public Teacher CheckLoding(String name, String password) {
// TODO Auto-generated method stub
Teacher teacher=null;
Connection conn=null;
Statement st=null;
ResultSet rs=null;
String sql="select * from teacher";
conn=DBO.getConnection();
try {
st=conn.createStatement();
rs=st.executeQuery(sql);
while(rs.next()) {
String nm=rs.getString("username");
String psd=rs.getString("password");
if(nm.equals(name)&& psd.equals(password)) {
teacher=new Teacher();
teacher.setUsername(nm);
teacher.setPassword(psd);
}
}
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return teacher;
}
@Override
public boolean Register(Teacher teacher) {
// TODO Auto-generated method stub
boolean flag=false;
String sql="insert into teacher(username,password) values(?,?)";
Connection conn=null;
PreparedStatement pst=null;
conn=DBO.getConnection();
try {
pst=conn.prepareStatement(sql);
pst.setString(1,teacher.getUsername());
pst.setString(2, teacher.getPassword());
pst.executeUpdate();
flag=true;
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return flag;
}
}
3建立老师的登录jsp
<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<html>
<head>
<base href="<%=basePath%>">
<title>学生管理系统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">
<style>
h1{font-family:华文行楷;}
h2{font-family:华文新魏;}
#btn1{
border:5px; outset #66CCFF; border-radius:15px;
width:100px;
height:30px;
padding:10px 20px;
font:bold 14px Tahoma;
color:#66CCFF;
box-shadow:3px 3px 3px #06C;
}
#btn3{
width:100px;
border:0;
font-size:20px;
font-family:黑体;
background-color:transparent;
}
#big{
width:800px;
height:600px;
}
#center{
width:500px;
height:10px;
margin-right:1px;
padding:3px;
}
a{text-decoration:none;}
style>
head>
<body >
<form action="TeacherCheakLogin" method="post">
<center>
<h1>教 师 登 录 界 面h1>
<div id="big"style="background-image:url(photo/12.jpg);background-position:center;background-repeat:no-repeat;">
<div style="padding-top:40px;">div>
<div id="center" align="center" style="padding-left:340px;">
<div style="padding-top:100px;">div>
<h2>用户名:<input id="btn1" type="text" name="username"style="height:30px;width:180px;border-radius=8px"/>h2>
<p style="padding-left:30px;"><h2>密 码:<input id="btn1" type="password" name="password"style="height:30px;width:180px;border-radius=8px"/>h2>
<h2>验证码:<input id="btn1" type="text" name="checkcode"style="height:30px;width:180px;border-radius=8px"/>h2>
<p style="padding-top:10px;"> <h2><img alt="验证码" src="PicCodeGenerator"><a href="teachercheck.jsp"> 看不清a>h2>p>
<p style="padding-top:10px;padding-left:150px;"><input id="btn3" type="submit" value="提交<<"> <br><br>
<a href="teacherregister.jsp">注册<<a><br><br>
<a href="index.jsp">返回<<a>
p>
div>
div>
center>
form>
body>
html>
以及相应的servlet
package cn.edu.hpu.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 cn.edu.hpu.dao.StudentManager;
import cn.edu.hpu.dao.TeacherManager;
import cn.edu.hpu.daoimpl.StudentManagerImpl;
import cn.edu.hpu.daoimpl.TeacherManagerImpl;
import cn.edu.hpu.domain.Student;
import cn.edu.hpu.domain.Teacher;
public class TeacherCheakLogin extends HttpServlet {
public void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
doPost(request, response);
}
public void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
request.setCharacterEncoding("utf-8");
response.setCharacterEncoding("utf-8");
String name=request.getParameter("username");
String password=request.getParameter("password");
String checkcode=request.getParameter("checkcode");
String piccode=(String) request.getSession().getAttribute("piccode");
TeacherManager smg = new TeacherManagerImpl();
Teacher t=new Teacher();
t.setUsername(name);
t.setPassword(password);
t=smg.CheckLoding(name,password);
if(t!=null && checkcode.equalsIgnoreCase(piccode)) {
response.sendRedirect("student.jsp");
}else{
response.sendRedirect("error.jsp");
}
}
}
接着写老师的注册jsp
<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<html>
<head>
<base href="<%=basePath%>">
<title>这是注册界面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">
<style type="text/css">
#top{
height:80px;
font-family:幼圆;
font-size:30px;
}
h2{font-family:华文新魏;}
#btn1{
border:5px; outset #66CCFF; border-radius:15px;
width:100px;
height:30px;
padding:10px 20px;
font:bold 14px Tahoma;
color:#66CCFF;
box-shadow:3px 3px 3px #06C;
}
a:link {
text-decoration: none;
}
a:visited {
text-decoration: none;
}
a:hover {
text-decoration: none;
}
a:active {
text-decoration: none;
}
style>
head>
<body background="photo/a.jpg">
<form action="TeacherRegister" method="post">
<div id="big">
<div id="top"><center><h1>欢 迎 来 到 注 册 界 面h1>center>div>
<div style="padding-left:660px;">
<br><br>
<h2>用户名:<input id="btn1" type="text" name="username"style="height:30px;width:330px;border-radius=8px"/>h2>
<h2>密 码:<input id="btn1" type="password"name="password" style="height:30px;width:330px;border-radius=8px">h2>
<h2>
验证码:<input id="btn1" type="text" name="checkcode" style="height:30px;width:330px;border-radius=8px"> <img alt="验证码" src="PicCodeGenerator"><a href="teacherregister.jsp">看不清a>h2>
<h2 style="padding-left:100px;"> <input id="btn1" type="submit" value="提交"/>
<input id="btn1" type="reset" value="重置"/> h2>
<br><br>
<a href="teachercheck.jsp" ><h1 style="padding-left:380px;">返回<<h1>a>
div>
div>
form>
body>
html>
以及注册的servlet
package cn.edu.hpu.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 cn.edu.hpu.dao.TeacherManager;
import cn.edu.hpu.daoimpl.TeacherManagerImpl;
import cn.edu.hpu.domain.Teacher;
public class TeacherRegister extends HttpServlet {
public void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
doPost(request, response);
}
public void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
request.setCharacterEncoding("utf-8");
response.setCharacterEncoding("utf-8");
String username=request.getParameter("username");
String password=request.getParameter("password");
String checkcode=request.getParameter("checkcode");
String piccode=(String) request.getSession().getAttribute("piccode");
System.out.println(username);
System.out.println(password);
TeacherManager tmg=new TeacherManagerImpl();
Teacher tea=new Teacher();
tea.setUsername(username);
tea.setPassword(password);
boolean flag=tmg.Register(tea);
if(flag &&checkcode.equalsIgnoreCase(piccode)) {
response.sendRedirect("error.jsp");
}else{
response.sendRedirect("error.jsp");
}
}
}
3接着写老师登陆成功后的jsp
<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<html>
<head>
<base href="<%=basePath%>">
<title>学生管理系统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="student.css">
<style type="text/css">
h1{
font-family:华文新魏;
font-size:50px;
}
#top{
width:1366px;
height:66px;
margin-right:1px;
padding:10px;
}
#left{
width:200px;
height:600px;
margin-right:2px;
padding:60px;
}
ul{
list-style-type:none;
margin:0;
padding:0;
}
a:link,a:visited
{
display:block;
font-weight:bold;
color:#FFFFFF;
background-color:#98bf21;
width:120px;
height:30px;
text-align:center;
padding:4px;
text-decoration:none;
text-transform:uppercase;
}
a:hover,a:active
{
background-color:#7A991A;
}
style>
head>
<body background="photo/88.jpg">
<div id="big">
<div id="top"><center><h1>学 生 管 理 系 统h1>center>div>
<div id="center">
<div id="left" align="left">
<div id="navigation" align="center">
<ul>
<li><a href="index.jsp">主页a>li>
<li><a href="add.jsp">增加a>li>
<li><a href="delete.jsp">删除a>li>
<li><a href="update.jsp">修改a>li>
<li><a href="student.jsp">作业a>li>
<li><a href="select.jsp">查询a>li>
<li><a href="student.jsp">通知a>li>
<li><a href="${pageContext.request.contextPath }/StudentServlet">学生信息a>li>
ul>
<div >div>
div>
div>
div>
<div id="bottem">div>
div>
body>
html>
4接着写老师可以对学生的操作
(1)增加学生信息
<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<html>
<head>
<title>增加学生信息title>
<meta charset="UTF-8">
<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="css/dong.css">
<script src="jquery-2.1.4.min.js">script>
<style type="text/css">
h1{font-family:华文行楷;}
h2{font-family:华文新魏;}
#btn1{
border:5px; outset #66CCFF;
border-radius:15px;
width:100px;
height:30px;
padding:10px 20px;
font:bold 14px Tahoma;
color:#66CCFF;
box-shadow:3px 3px 3px #06C;
}
#big{
width:1300px;
height:550px;
}
a:link {
text-decoration: none;
}
a:visited {
text-decoration: none;
}
a:hover {
text-decoration: none;
}
a:active {
text-decoration: none;
}
body{
text-align:center;
}
style>
head>
<body>
<form action="Register" method="post" id="form1">
<div id="big"style="background-image:url(photo/1.jpg);background-position:center;background-repeat:no-repeat;">
<div id="top" align="center"><h1>增 加 学 生 信 息h1>div><br><br>
<div id="center" align="center">
<h2>学 号:<input id="btn1" type="text" name="sid" style="height:35px;width:330px;border-radius=8px"/>h2>
<h2>姓 名:<input id="btn1" type="text" name="username"style="height:35px;width:330px;border-radius=8px"/>h2>
<h2>密 码:<input id="btn1" type="number" name="password" style="height:35px;width:330px;border-radius=8px">h2>
<h2>生 日:<input id="btn1" type="date" name="birthday" style="height:35px;width:330px;border-radius=8px"/><h2>
验 证 码:<input id="btn1" type="text" name="checkcode" style="height:35px;width:330px;border-radius=8px"> <img alt="验证码" src="PicCodeGenerator"><a href="add.jsp">看不清a>h2>
<h2>家庭地址:<input id="btn1" type="text" name="address" style="height:35px;width:330px;border-radius=8px">h2>
<center style="padding-left:90px"><h2><input type="radio" name="gender" value="男生"/>男生
<input type="radio" name="gender" value="女生"/>女生 <br>h2>center>
<section class="buttons">
<div class="btn btn-4">
<input id="btn9" type="submit" value="提交"/>
div>
<div class="btn btn-4"><input id="reset" type="reset" value="重置"/>div>
section>
div>
div>
form>
body>
html>
<script>
$(function(){
$(".btn-1").click(function(){
$("#form1").submit();
});
});
script>
以及相应的servlet
package cn.edu.hpu.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 cn.edu.hpu.dao.StudentManager;
import cn.edu.hpu.daoimpl.StudentManagerImpl;
import cn.edu.hpu.domain.Student;
public class Register extends HttpServlet {
public void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
doPost(request, response);
}
public void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
request.setCharacterEncoding("utf-8");
request.setCharacterEncoding("utf-8");
String sid=request.getParameter("sid");
String username=request.getParameter("username");
//username=new String(username.getBytes("ISO-8859-1"),"utf-8");
String password=request.getParameter("password");
String birthday=request.getParameter("birthday");
String address=request.getParameter("address");
String checkcode=request.getParameter("checkcode");
String gender=request.getParameter("gender");
String piccode=(String) request.getSession().getAttribute("piccode");
StudentManager smg=new StudentManagerImpl();
Student s=new Student();
s.setName(username);
s.setSid(sid);
s.setPassword(password);
s.setGender(gender);
s.setBirthday(birthday);
s.setAddress(address);
boolean flag=smg.addStudent(s);
//flag=umg.Register(u);
if(flag && checkcode.equalsIgnoreCase(piccode)) {
response.sendRedirect("success.jsp");
}else{
response.sendRedirect("error.jsp");
}
}
}
(2)删除学生信息
<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<%@ page contentType="text/html;charset=utf-8"%>
<html>
<head>
<base href="<%=basePath%>">
<title>删除学生信息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">
<style type="text/css">
h1{font-family:华文行楷;}
#btn1{
border:5px; outset #66CCFF; border-radius:15px;
width:100px;
height:30px;
padding:10px 20px;
font:bold 14px Tahoma;
color:#66CCFF;
box-shadow:3px 3px 3px #06C;
}
#big{
width:1300px;
height:550px;
}
a:link {
text-decoration: none;
}
a:visited {
text-decoration: none;
}
a:hover {
text-decoration: none;
}
a:active {
text-decoration: none;
}
a.two:link {color:#ff0000;}
a.two:visited {color:#0000ff;}
a.two:hover {font-size:150%;}
style>
head>
<body>
<form action="Delete" method="post">
<div id="big"style="background-image:url(photo/1.jpg);background-position:center;background-repeat:no-repeat;">
<div id="top" align="center"><h1>删 除 学 生 信 息h1>div><br><br>
<div id="center" align="center" style="padding-top:100px;">
<h2>学 号:<input id="btn1" type="text" name="sid"style="height:30px;width:330px;border-radius=8px"/>h2>
<h2 style="padding-left:150px;padding-top:30px;"><input id="btn1" type="submit" value="提交"/>
<input id="btn1" type="reset" value="重置"/> <a class="two" href="student.jsp">返回<<a>h2>
div>
div>
form>
body>
html>
以及相应的servlet
package cn.edu.hpu.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 cn.edu.hpu.dao.StudentManager;
import cn.edu.hpu.daoimpl.StudentManagerImpl;
public class Delete extends HttpServlet {
public void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
doPost(request, response);
}
public void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
request.setCharacterEncoding("utf-8");
request.setCharacterEncoding("utf-8");
String sid=request.getParameter("sid");
System.out.println(sid);
StudentManager smg=new StudentManagerImpl();
boolean flag=smg.deleteStudent(sid);
if(flag) {
response.sendRedirect("success.jsp");
}else{
response.sendRedirect("error.jsp");
}
}
}
(3)修改学生信息
<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<html>
<head>
<base href="<%=basePath%>">
<title>修改学生信息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">
<style type="text/css">
h1{font-family:华文行楷;}
h2{font-family:华文新魏;}
#btn1{
border:5px; outset #66CCFF; border-radius:15px;
width:100px;
height:30px;
padding:10px 20px;
font:bold 14px Tahoma;
color:#66CCFF;
box-shadow:3px 3px 3px #06C;
}
#big{
width:1300px;
height:550px;
}
a:link {
text-decoration: none;
}
a:visited {
text-decoration: none;
}
a:hover {
text-decoration: none;
}
a:active {
text-decoration: none;
}
a.two:link {color:#ff0000;}
a.two:visited {color:#0000ff;}
a.two:hover {font-size:150%;}
style>
head>
<body>
<form action="Update" method="post">
<div id="big"style="background-image:url(photo/1.jpg);background-position:center;background-repeat:no-repeat;">
<div id="top" align="center"><h1>修 改 学 生 信 息h1>div><br><br>
<div id="center" align="center">
<h2>学 号:<input id="btn1" type="text" name="sid" style="height:30px;width:330px;border-radius=8px"/>h2>
<h2>姓 名<input id="btn1" type="text" name="username"style="height:30px;width:330px;border-radius=8px"/>h2>
<h2>密 码:<input id="btn1" type="password"name="password" style="height:30px;width:330px;border-radius=8px">h2>
<h2>生 日:<input id="btn1" type="date" name="birthday"style="height:30px;width:330px;border-radius=8px"/>h2>
<h2>家庭地址:<input id="btn1" type="text" name="address" style="height:30px;width:330px;border-radius=8px">h2>
<center style="padding-left:90px"><h2><input type="radio" name="gender" value="男生"/>男生
<input type="radio" name="gender" value="女生"/>女生 <br>h2>center>
<center style="padding-left:100px">
<h2><input id="btn1" type="submit" value="提交"/>
<input id="btn1" type="reset" value="重置"/> <a class="two" href="student.jsp">返回<<a>h2>center>
div>
div>
form>
body>
html>
相应的servlet
package cn.edu.hpu.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 cn.edu.hpu.dao.StudentManager;
import cn.edu.hpu.daoimpl.StudentManagerImpl;
import cn.edu.hpu.domain.Student;
public class Update extends HttpServlet {
public void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
doPost(request, response);
}
public void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
request.setCharacterEncoding("utf-8");
response.setCharacterEncoding("utf-8");
String sid=request.getParameter("sid");
String name=request.getParameter("username");
String password=request.getParameter("password");
String gender=request.getParameter("gender");
String birthday=request.getParameter("birthday");
String address=request.getParameter("address");
Student s= new Student();
StudentManager smg = new StudentManagerImpl();
s.setSid(sid);
s.setName(name);
s.setPassword(password);
s.setGender(gender);
s.setBirthday(birthday);
s.setAddress(address);
boolean flag=smg.updateStudent(sid, s);
if(flag) {
response.sendRedirect("success.jsp");
}else{
response.sendRedirect("error.jsp");
}
}
}
(4)查询学生信息
<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<html>
<head>
<base href="<%=basePath%>">
<title>查询学生信息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">
<style type="text/css">
h1{font-family:华文行楷;}
h2{font-family:华文新魏;}
#btn1{
border:5px; outset #66CCFF; border-radius:15px;
width:100px;
height:30px;
padding:10px 20px;
font:bold 14px Tahoma;
color:#66CCFF;
box-shadow:3px 3px 3px #06C;
}
#big{
width:1300px;
height:550px;
}
a:link {
text-decoration: none;
}
a:visited {
text-decoration: none;
}
a:hover {
text-decoration: none;
}
a:active {
text-decoration: none;
}
a.two:link {color:#ff0000;}
a.two:visited {color:#0000ff;}
a.two:hover {font-size:150%;}
style>
head>
<body>
<form action="Select" method="post">
<div id="big"style="background-image:url(photo/1.jpg);background-position:center;background-repeat:no-repeat;">
<div id="top" align="center"><h1>查 询 学 生 信 息h1>div><br><br>
<div id="center" align="center" style="padding-top:100px;">
<h2>学 号:<input id="btn1" type="text" name="sid"style="height:30px;width:330px;border-radius=8px"/>h2>
<h2 style="padding-left:150px;padding-top:30px;"><input id="btn1" type="submit" value="提交"/>
<input id="btn1" type="reset" value="重置"/> <a class="two" href="student.jsp">返回<<a>h2>center>
div>
div>
form>
body>
html>
以及相应的servelt
package cn.edu.hpu.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 cn.edu.hpu.dao.StudentManager;
import cn.edu.hpu.daoimpl.StudentManagerImpl;
import cn.edu.hpu.domain.Student;
public class Select extends HttpServlet {
public void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
doPost(request, response);
}
public void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
request.setCharacterEncoding("utf-8");
response.setCharacterEncoding("utf-8");
String sid=(String) request.getParameter("sid");
StudentManager st=new StudentManagerImpl();
Student s=new Student();
List list=st.getAllStudent(sid);
s=list.get(0);
request.setAttribute("s", s);
if(s!=null) {
request.getRequestDispatcher("selectstudent.jsp").forward(request, response); System.out.println("ok");
}else{
response.sendRedirect("error.jsp");
}
}
}
以及要查询学生的详细信息
<%@ page language="java" import="java.util.*,cn.edu.hpu.daoimpl.*,cn.edu.hpu.dao.*,cn.edu.hpu.domain.*" pageEncoding="utf-8"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<html>
<head>
<base href="<%=basePath%>">
<title>查询到的学生信息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">
<style type="text/css">
h1{
font-family:华文行楷;
font-size:50px;
}
h2{font-family:华文新魏;}
#big{
width:1300px;
height:550px;
}
#customers
{
font-family:"Trebuchet MS", Arial, Helvetica, sans-serif;
width:50%;
border-collapse:collapse;
}
#customers td, #customers th
{
font-size:1em;
border:1px solid #98bf21;
padding:3px 7px 2px 7px;
}
#customers th
{
font-size:1.1em;
text-align:left;
padding-top:5px;
padding-bottom:4px;
background-color:#A7C942;
color:#ffffff;
}
#customers tr.alt td
{
color:#000000;
background-color:#EAF2D3;
}
style>
head>
<body background="photo/99.jpg">
<form action="Register" method="post">
<div id="big">
<center><h1>该 学 生 的 信 息h1>center>
<center>
<p style="padding-top:180px">
<table border=1 id="customers">
<tr>
<th><h2>学号h2>th>
<th><h2>姓名h2>th>
<th><h2>密码h2>th>
<th><h2>性别h2>th>
<th><h2>生日h2>th>
<th><h2>地址h2>th>
tr>
<%
Student s=(Student) request.getAttribute("s");
%>
<tr class="alt">
<td><h2><%=s.getSid() %>h2>td>
<td><h2><%=s.getName() %>h2>td>
<td><h2><%=s.getPassword() %>h2>td>
<td><h2><%=s.getGender() %>h2>td>
<td><h2><%=s.getBirthday() %>h2>td>
<td><h2><%=s.getAddress() %>h2>td>
tr>
table>
center>
div>
form>
body>
html>
(5)分页的所有信息
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<html>
<head>
<title>学生信息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">
<style type="text/css">
h1{
font-family:华文行楷;
font-size:50px;
}
h2{font-family:华文新魏;}
#big{
width:1300px;
height:550px;
}
#customers
{
font-family:"Trebuchet MS", Arial, Helvetica, sans-serif;
width:50%;
border-collapse:collapse;
}
#customers td, #customers th
{
font-size:1em;
border:1px solid #98bf21;
padding:3px 7px 2px 7px;
}
#customers th
{
font-size:1.1em;
text-align:left;
padding-top:5px;
padding-bottom:4px;
background-color:#A7C942;
color:#ffffff;
}
#customers tr.alt td
{
color:#000000;
background-color:#EAF2D3;
}
style>
head>
<body background="photo/99.jpg">
<center>
<div id="big">
<center><h1>学 生 信 息h1>center>
<center>
<p style="padding-top:60px;">
<table border=1 id="customers" >
<tr>
<th>学号th>
<th>姓 名th>
<th>密 码th>
<th>性 别th>
<th>生 日th>
<th>住 址th>
tr>
<c:forEach items="${pb.beanlist }" var="student">
<tr class="alt">
<td>${student.sid }td>
<td>${student.name }td>
<td>${student.password }td>
<td>${student.gender }td>
<td>${student.birthday }td>
<td>${student.address }td>
tr>
c:forEach>
table>
<%@ include file="/page.jsp" %>
center>
div>
center>
body>
html>
二.接着写学生的相关操作
1.学生的基本信息
package cn.edu.hpu.domain;
public class Student {
private int id;
private String sid;
private String name;
private String password;
private String gender;
private String birthday;
private String address;
public String getPassword() {
return password;
}
public void setPassword(String password) {
this.password = password;
}
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public String getSid() {
return sid;
}
public void setSid(String sid) {
this.sid = sid;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getGender() {
return gender;
}
public void setGender(String gender) {
this.gender = gender;
}
public String getBirthday() {
return birthday;
}
public void setBirthday(String birthday) {
this.birthday = birthday;
}
public String getAddress() {
return address;
}
public void setAddress(String address) {
this.address = address;
}
}
2学生的登录注册增删改查的接口
package cn.edu.hpu.dao;
import java.util.List;
import cn.edu.hpu.domain.Student;
public interface StudentManager {
//登录时
public Student CheckLogin(String name,String sid,String password);
//添加学生信息
public boolean addStudent(Student student);
//更新学生信息
public boolean updateStudent(String sid,Student student);
//删除学生信息
public boolean deleteStudent(String sid);
//查询所有的学生信息
public List getAllStudent(String sid);
}
以及相应的实现类
package cn.edu.hpu.daoimpl;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.ArrayList;
import java.util.List;
import cn.edu.hpu.dao.StudentManager;
import cn.edu.hpu.domain.Student;
import cn.edu.hpu.util.DBO;
public class StudentManagerImpl implements StudentManager {
@Override
public Student CheckLogin(String name, String sid,String password) {
// TODO Auto-generated method stub
Student s=null;
Connection conn=null;
Statement st=null;
ResultSet rs=null;
String sql="select * from student";
conn=DBO.getConnection();
try {
st=conn.createStatement();
rs=st.executeQuery(sql);
while(rs.next()) {
String nm=rs.getString("name");
String id=rs.getString("sid");
String psd=rs.getString("password");
if(nm.equals(name) && id.equals(sid) && psd.equals(password)) {
s= new Student();
s.setName(nm);
s.setSid(id);
s.setPassword(psd);
s.setGender(rs.getString("gender"));
s.setAddress(rs.getString("address"));
s.setId(rs.getInt("id"));
s.setBirthday(rs.getString("birthday"));
}
}
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return s;
}
@Override
public boolean addStudent(Student student) {
// TODO Auto-generated method stub
boolean flag=false;
String sql="insert into student(sid,name,password,gender,birthday,address) values(?,?,?,?,?,?)";
Connection conn=null;
PreparedStatement pst=null;
conn=DBO.getConnection();
try {
pst=conn.prepareStatement(sql);
pst.setString(1,student.getSid());
pst.setString(2,student.getName());
pst.setString(3, student.getPassword());
pst.setString(4,student.getGender());
pst.setString(5,student.getBirthday());
pst.setString(6,student.getAddress());
pst.executeUpdate();
flag=true;
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return flag;
}
@Override
public boolean updateStudent(String sid, Student student) {
// TODO Auto-generated method stub
boolean flag=false;
String sql="update student set name=?,password=?,gender=?,birthday=?,address=? where sid='"+sid+"'";
Connection conn=null;
PreparedStatement pst=null;
conn=DBO.getConnection();
try {
pst=conn.prepareStatement(sql);
pst.setString(1,student.getName());
pst.setString(2,student.getPassword());
pst.setString(3,student.getGender());
pst.setString(4,student.getBirthday());
pst.setString(5,student.getAddress());
pst.executeUpdate();
flag=true;
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return flag;
}
@Override
public boolean deleteStudent(String sid) {
// TODO Auto-generated method stub
boolean flag=false;
String sql="delete from student where sid='"+sid+"'";
System.out.println(sql);
Connection conn=null;
PreparedStatement pst=null;
conn=DBO.getConnection();
try {
pst=conn.prepareStatement(sql);
int row=pst.executeUpdate();
if(row>0)
flag=true;
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return flag;
}
@Override
public List getAllStudent(String sid) {
// TODO Auto-generated method stub
List list=new ArrayList();
String sql="select * from student where sid='"+sid+"'";
Connection conn=null;
Statement st=null;
ResultSet rs=null;
conn=DBO.getConnection();
try {
st=conn.createStatement();
rs=st.executeQuery(sql);
while(rs.next()) {
Student s=new Student();
s.setSid(sid);
s.setName(rs.getString("name"));
s.setPassword(rs.getString("password"));
s.setGender(rs.getString("gender"));
s.setBirthday(rs.getString("birthday"));
s.setAddress(rs.getString("address"));
list.add(s);
}
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return list;
}
}
3.学生的登录jsp
<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<html>
<head>
<base href="<%=basePath%>">
<title>学生管理系统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">
<style>
#title{
height:80px;
font-family:幼圆;
font-size:30px;
}
#center{
width:500px;
height:10px;
margin-right:1px;
padding:3px;
}
style>
head>
<body background="photo/7.jpg">
<form action="CheckLogin" method="post">
<div id="title"><center><h1>学 生 登 陆 界 面h1>center>div>
<br><br><br><br><br><br><br><br><br><br><br>
<center>
<div class="center">
<table>
<tr>
<td> 用户名:td>
<td><input name="username" type="text">input>td>
tr>
<tr>
<td> 学 号:td>
<td><input name="sid" type="text">input>td>
tr>
<tr>
<td> 密 码:td>
<td><input name="password" type="password">td>
tr>
<tr>
<td> 验证码:td>
<td><input type="text" name="checkcode"> <img alt="验证码" src="PicCodeGenerator"><a href="studentCheck.jsp">看不清a>td>
tr>
table>
<input type="submit" value="提交">
<input type="reset" value="重置"> <br><br>
<a href="studentregister.jsp">注册a>
<a href="index.jsp">返回a>
div>
center>
form>
body>
html>
以及相应的servlet
package cn.edu.hpu.servlet;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import cn.edu.hpu.dao.StudentManager;
import cn.edu.hpu.daoimpl.StudentManagerImpl;
import cn.edu.hpu.domain.Student;
public class CheckLogin extends HttpServlet {
public void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
doPost(request, response);
}
public void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
request.setCharacterEncoding("utf-8");
response.setCharacterEncoding("utf-8");
String name=request.getParameter("username");
String sid=request.getParameter("sid");
String password=request.getParameter("password");
/*System.out.println(name);
System.out.println(sid);
System.out.println(password);*/
//request.getSession().setAttribute("sid", sid);
String checkcode=request.getParameter("checkcode");
//System.out.println(checkcode);
String piccode=(String) request.getSession().getAttribute("piccode");
//System.out.println(piccode);
StudentManager smg = new StudentManagerImpl();
Student s=new Student();
s=smg.CheckLogin(name, sid,password);
request.setAttribute("s", s);
//request.setAttribute("sid", sid);
//request.getSession().setAttribute("student", s);
HttpSession session=request.getSession();
session.setAttribute("stu", s);
if(s!=null && checkcode.equalsIgnoreCase(piccode)) {
response.sendRedirect("person.jsp");
}else{
response.sendRedirect("error.jsp");
}
}
}
(2)注册jsp
<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<html>
<head>
<base href="<%=basePath%>">
<title>这是注册界面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">
<style type="text/css">
#top{
height:80px;
font-family:幼圆;
font-size:30px;
}
h2{font-family:华文新魏;}
#btn1{
border:5px; outset #66CCFF; border-radius:15px;
width:100px;
height:30px;
padding:10px 20px;
font:bold 14px Tahoma;
color:#66CCFF;
box-shadow:3px 3px 3px #06C;
}
a:link {
text-decoration: none;
}
a:visited {
text-decoration: none;
}
a:hover {
text-decoration: none;
}
a:active {
text-decoration: none;
}
style>
head>
<body background="photo/a.jpg">
<form action="Register" method="post">
<div id="big">
<div id="top"><center><h1>欢 迎 来 到 注 册 界 面h1>center>div>
<div style="padding-left:660px;">
<br><br>
<h2>学 号:<input id="btn1" type="text" name="sid" style="height:30px;width:330px;border-radius=8px">h2>
<h2>用户名:<input id="btn1" type="text" name="username"style="height:30px;width:330px;border-radius=8px"/>h2>
<h2>密 吗:<input id="btn1" type="password"name="password" style="height:30px;width:330px;border-radius=8px">h2>
<h2>
验 证码:<input id="btn1" type="text" name="checkcode" style="height:30px;width:330px;border-radius=8px">h2>
<h2>生 日:<input type="date" name="birthday"/> <img alt="验证码" src="PicCodeGenerator"><a href="studentregister.jsp">看不清a>
<h2>住 址:<input id="btn1" type="text"name="address" style="height:30px;width:330px;border-radius=8px">h2>
<h2 style="padding-left:100px;"><input type="radio" name="gender" value="男生"/>男生 <input type="radio" name="gender" value="女生"/>女生h2>
<h2 style="padding-left:100px;"> <input id="btn1" type="submit" value="提交"/>
<input id="btn1" type="reset" value="重置"/> h2>
<a href="studentCheck.jsp" ><h1 style="padding-left:380px;">返回<<h1>a>
div>
div>
form>
body>
html>
以及相应的servlet
package cn.edu.hpu.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 cn.edu.hpu.dao.StudentManager;
import cn.edu.hpu.daoimpl.StudentManagerImpl;
import cn.edu.hpu.domain.Student;
public class Register extends HttpServlet {
public void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
doPost(request, response);
}
public void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
request.setCharacterEncoding("utf-8");
request.setCharacterEncoding("utf-8");
String sid=request.getParameter("sid");
String username=request.getParameter("username");
//username=new String(username.getBytes("ISO-8859-1"),"utf-8");
String password=request.getParameter("password");
String birthday=request.getParameter("birthday");
String address=request.getParameter("address");
String checkcode=request.getParameter("checkcode");
String gender=request.getParameter("gender");
String piccode=(String) request.getSession().getAttribute("piccode");
StudentManager smg=new StudentManagerImpl();
Student s=new Student();
s.setName(username);
s.setSid(sid);
s.setPassword(password);
s.setGender(gender);
s.setBirthday(birthday);
s.setAddress(address);
boolean flag=smg.addStudent(s);
//flag=umg.Register(u);
if(flag && checkcode.equalsIgnoreCase(piccode)) {
response.sendRedirect("success.jsp");
}else{
response.sendRedirect("error.jsp");
}
}
}
(3)学生登陆成功后的界面
<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<html>
<head>
<base href="<%=basePath%>">
<title>学生信息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="css/buttun.css">
<style type="text/css">
ul{
list-style-type:none;
margin:0;
padding:0;
overflow:hidden;
}
li{
float:left;
}
a:link,a:visited{
display:block;
width:120px;
font-weight:bold;
color:#FFFFFF;
background-color:#98bf21;
text-align:center;
padding:4px;
text-decoration:none;
text-transform:uppercase;
}
a:hover,a:active {
background-color:#7A991A;
}
.center
{
margin:auto;
width:50%;
}
h1{
font-family:华文行楷;
font-size:50px;
}
#left{
border-radius:50px;
width:100px;
height:60px;
text-align: center;
transition:background-color,transform 1s linear 0s;
-moz-transition:background-color,transform 1s linear 0s;
-webkit-transition:background-color,transform 1s linear 0s;
-o-transition:background-color,transform 1s linear 0s;
}
#left:hover{
/*指定变形方式*/
-ms-transform: rotate(360deg) scale(1.2,1.2) ;
-moz-transform:rotate(360deg) scale(1.2,1.2);
-webkit-transform:rotate(360deg) scale(1.2,1.2);
-o-transform:rotate(360deg) scale(1.2,1.2);
transform:rotate(360deg) scale(1.2,1.2);
}
style>
head>
<body background="photo/88.jpg">
<form action="Register">
<div class="big">
<div id="head">
<span style="cursor:crosshair"><center><h1>个 人 信 息h1>center>span>
<br>
div>
<div class="center" style="padding-top:30px;">
<ul >
<li><a href="index.jsp">主页a>li>
<li><a href="one.jsp">个人信息a>li>
<li><a href="updatestudent.jsp">修改个人信息a>li>
<li><a href="#">作业a>li>
<li><a href="${pageContext.request.contextPath }/StudentServlet1">花名册a>li>
ul>
<br><br><br>
div>
<p style="padding-top:200px">
<div id="left"><a href="studentCheck.jsp"> 退出a>div>
div>
form>
body>
html>
(4)修改个人信息
<%@ page language="java" import="java.util.*,cn.edu.hpu.daoimpl.*,cn.edu.hpu.domain.*" pageEncoding="utf-8"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<html>
<head>
<base href="<%=basePath%>">
<title>修改个人信息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">
<style>
h1{
font-family:华文行楷;
font-size:50px;
}
#btn1{
border:5px; outset #66CCFF; border-radius:15px;
width:100px;
height:30px;
padding:10px 20px;
font:bold 14px Tahoma;
color:#66CCFF;
box-shadow:3px 3px 3px #06C;
}
a.two:link {color:#ff0000;}
a.two:visited {color:#0000ff;}
a.two:hover {font-size:150%;}
style>
head>
<body background="photo/333.jpg">
<form action="Update">
<%
Student s=(Student)request.getSession().getAttribute("stu");
if(s==null)
s = new Student();
%>
<div id="big">
<div id="top" align="center"><h1>修 改 学 生 信 息h1>div><br><br>
<div id="center" style="padding-left:600px">
<h2>学 号:<input id="btn1" type="text" name="sid" value="<%=s.getSid() %>"οnfοcus=this.blur() style="height:30px;width:330px;border-radius=8px"/>h2>
<h2>姓 名:<input id="btn1" type="text" name="username"style="height:30px;width:330px;border-radius=8px"/>h2>
<h2>密 码:<input id="btn1" type="password"name="password" style="height:30px;width:330px;border-radius=8px">h2>
<h2>生 日:<input id="btn1" type="date" name="birthday"style="height:30px;width:330px;border-radius=8px"/>h2>
<h2>家庭地址:<input id="btn1" type="text" name="address" style="height:30px;width:330px;border-radius=8px">h2>
<center ><h2><input type="radio" name="gender" value="男生"/>男生
<input type="radio" name="gender" value="女生"/>女生 <br>h2>center>
<center style="padding-left:80px">
<h2><input id="btn1" type="submit" value="提交"/>
<input id="btn1" type="reset" value="重置"/> <a class="two" href="person.jsp" target="_blank">返回<<a>h2>center>
div>
div>
form>
body>
html>
(5)查询个人信息
<%@ page language="java" import="java.util.*,cn.edu.hpu.daoimpl.*,cn.edu.hpu.domain.*" pageEncoding="utf-8"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<html>
<head>
<base href="<%=basePath%>">
<title>个人信息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">
<style type="text/css">
#customers
{
font-family:"Trebuchet MS", Arial, Helvetica, sans-serif;
width:50%;
border-collapse:collapse;
}
#customers td, #customers th
{
font-size:1em;
border:1px solid #98bf21;
padding:3px 7px 2px 7px;
}
#customers th
{
font-size:1.1em;
text-align:left;
padding-top:5px;
padding-bottom:4px;
background-color:#A7C942;
color:#ffffff;
}
#customers tr.alt td
{
color:#000000;
background-color:#EAF2D3;
}
h1{
font-family:华文行楷;
font-size:50px;
}
style>
head>
<body background=photo/99.jpg>
<div id="big">
<div id="top"><center><span style="cursor:move"><h1>个 人 详 细 信 息h1>span><br>center>div>
<div id="center" align="center" style="padding-top:130px">
<table border=1 id="customers">
<tr>
<th><h2>学号h2>th>
<th><h2>姓名h2>th>
<th><h2>密码h2>th>
<th><h2>性别h2>th>
<th><h2>生日h2>th>
<th><h2>地址h2>th>
tr>
<%
Student s=(Student)request.getSession().getAttribute("stu");
if(s==null)
s = new Student();
%>
<tr class="alt">
<td><h2><%=s.getSid() %>h2>td>
<td><h2><%=s.getName() %>h2>td>
<td><h2><%=s.getPassword() %>h2>td>
<td><h2><%=s.getGender() %>h2>td>
<td><h2><%=s.getBirthday() %>h2>td>
<td><h2><%=s.getAddress() %>h2>td>
tr>
table>
div>
div>
body>
html>
(6)查看他人信息
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<html>
<head>
<title>学生信息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">
<style type="text/css">
h1{
font-family:华文行楷;
font-size:50px;
}
h2{font-family:华文新魏;}
#big{
width:1300px;
height:550px;
}
#customers
{
font-family:"Trebuchet MS", Arial, Helvetica, sans-serif;
width:50%;
border-collapse:collapse;
}
#customers td, #customers th
{
font-size:1em;
border:1px solid #98bf21;
padding:3px 7px 2px 7px;
}
#customers th
{
font-size:1.1em;
text-align:left;
padding-top:5px;
padding-bottom:4px;
background-color:#A7C942;
color:#ffffff;
}
#customers tr.alt td
{
color:#000000;
background-color:#EAF2D3;
}
style>
head>
<body background="photo/99.jpg">
<center>
<div id="big">
<center><h1>学 生 信 息h1>center>
<center>
<p style="padding-top:60px;">
<table border=1 id="customers" >
<tr>
<th>学号th>
<th>姓 名th>
<th>性 别th>
<th>生 日th>
<th>住 址th>
tr>
<c:forEach items="${pb.beanlist }" var="student">
<tr class="alt">
<td>${student.sid }td>
<td>${student.name }td>
<td>${student.gender }td>
<td>${student.birthday }td>
<td>${student.address }td>
tr>
c:forEach>
table>
<%@ include file="/page.jsp" %>
center>
div>
center>
body>
html>
(6)查看他人信息
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<html>
<head>
<title>学生信息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">
<style type="text/css">
h1{
font-family:华文行楷;
font-size:50px;
}
h2{font-family:华文新魏;}
#big{
width:1300px;
height:550px;
}
#customers
{
font-family:"Trebuchet MS", Arial, Helvetica, sans-serif;
width:50%;
border-collapse:collapse;
}
#customers td, #customers th
{
font-size:1em;
border:1px solid #98bf21;
padding:3px 7px 2px 7px;
}
#customers th
{
font-size:1.1em;
text-align:left;
padding-top:5px;
padding-bottom:4px;
background-color:#A7C942;
color:#ffffff;
}
#customers tr.alt td
{
color:#000000;
background-color:#EAF2D3;
}
style>
head>
<body background="photo/99.jpg">
<center>
<div id="big">
<center><h1>学 生 信 息h1>center>
<center>
<p style="padding-top:60px;">
<table border=1 id="customers" >
<tr>
<th>学号th>
<th>姓 名th>
<th>性 别th>
<th>生 日th>
<th>住 址th>
tr>
<c:forEach items="${pb.beanlist }" var="student">
<tr class="alt">
<td>${student.sid }td>
<td>${student.name }td>
<td>${student.gender }td>
<td>${student.birthday }td>
<td>${student.address }td>
tr>
c:forEach>
table>
<%@ include file="/page.jsp" %>
center>
div>
center>
body>
html>
最后补充才开始的界面
<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<html>
<head>
<base href="<%=basePath%>">
<title>学生管理系统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">
<script src="js/jquery-2.1.4.min.js">script>
<script>
$(function(){
$("#lefta").mouseenter(function(){
$("#lefta").css({"left":"20%"});
});
$("#lefta").mouseleave(function(){
$("#lefta").css({"left":"10%"});
});
});
script>
<style>
*{margin: 0;padding: 0;}
#lefta{position: absolute;left: 20%;
transition: all 0.5s;
-moz-transition: all 0.5s; /* Firefox 4 */
-webkit-transition: all 0.5s; /* Safari 和 Chrome */
-o-transition: all 0.5s; /* Opera */
}
h1{font-family:华文行楷;}
#top{
width:1300px;
font-size:30px;
}
#left{
border-radius:50px;
width:100px;
height:60px;
background-color: light blue;
color:white;
text-align: center;
transition:background-color,transform 1s linear 0s;
-moz-transition:background-color,transform 1s linear 0s;
-webkit-transition:background-color,transform 1s linear 0s;
-o-transition:background-color,transform 1s linear 0s;
}
#left:hover{
background-color: blue;
/*指定变形方式*/
-ms-transform: rotate(360deg) scale(1.2,1.2) ;
-moz-transform:rotate(360deg) scale(1.2,1.2);
-webkit-transform:rotate(360deg) scale(1.2,1.2);
-o-transform:rotate(360deg) scale(1.2,1.2);
transform:rotate(360deg) scale(1.2,1.2);
}
#big{
width:1300px;
height:600px;
}
#top{
width:1300px;
height:200px;
}
#center{
width:1366px;
height:400px;
font-size:20px;
font-family:华文行楷;
}
#lefta{
width:500px;
height:400px;
}
#righta{
width:760px;
height:400px;
}
a{text-decoration:none;}
style>
head>
<body background="photo/a.jpg">
<div id="big">
<div id="top" align="center"><h1>简 单 的 学 生 管 理 系 统h1>div>
<div id="center">
<div id="lefta">
<img src="photo/demo.png" alt="">
div>
<div id="right" align="center">
<fieldset style="height:300px;width:500px;">
<legend ><div id="head" ><h1>您的身份是h1>div>legend><br><br><br>
<div id="left"><a href="teachercheck.jsp"><h1>教师h1>a><br>div><br>
<div id="left" align="center"><a href="studentCheck.jsp"><h1>学生h1>a>div>
fieldset>
div>
div>
div>
body>
html>
操作成功的jsp
<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<html>
<head>
<base href="<%=basePath%>">
<title>操作成功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">
<style type="text/css">
h1{font-family:华文彩云;}
h1{font-size:36px}
#big{
width:800px;
height:600px;
margin-right:1px;
}
#top{
width:800px;
height:200px;
margin-right:1px;
padding:3px;
}
style>
head>
<body>
<center>
<div id="big" style="background-image:url(photo/6.jpg);background-position:center;background-repeat:no-repeat;">
<div id="top">div>
<div id="center">
<h1>恭喜您操作成功!!!h1><br><br><br>
<a href="studentCheck.jsp">学生登录a>
<a href="studentregister.jsp">学生注册a>
<a href="teachercheck.jsp">教师登录a>
<a href="teacherregister.jsp">教师注册a>
div>
div>
center>
body>
html>
操作失败的jsp
<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<html>
<head>
<base href="<%=basePath%>">
<title>输入的信息有误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">
<style type="text/css">
h1{font-family:华文彩云;}
h1{font-size:36px}
#big{
width:800px;
height:600px;
margin-right:1px;
}
#top{
width:800px;
height:200px;
margin-right:1px;
padding:3px;
}
style>
head>
<body>
<center>
<div id="big" style="background-image:url(photo/6.jpg);background-position:center;background-repeat:no-repeat;">
<div id="top">div>
<div id="center">
<h1>Sorry 您操作有误!!!h1><br><br><br>
<a href="studentCheck.jsp">学生登录a>
<a href="studentregister.jsp">学生注册a>
<a href="teachercheck.jsp">教师登录a>
<a href="teacherregister.jsp">教师注册a>
div>
div>
center>
body>
html>
以及用到的css
* {
-webkit-transition-property: all;
transition-property: all;
-webkit-transition-duration: .6s;
transition-duration: .6s;
-webkit-transition-timing-function: ease;
transition-timing-function: ease;
}
body {
font-family: 'Roboto', sans-serif;
font-weight: 400;
}
.buttons {
display: table;
width: 100%;
position: relative;
}
.container {
display: table-cell;
padding: 1em;
text-align: center;
vertical-align: middle;
}
.btn {
color: #fff;
cursor: pointer;
display: block;
font-size: 16px;
font-weight: 400;
line-height: 45px;
margin: 0 auto 2em;
max-width: 160px;
position: relative;
text-decoration: none;
text-transform: uppercase;
vertical-align: middle;
width: 100%;
display: inline-block;
}
#btn9{
border: 0;
background: none;
font-size: 22px;
line-height: 45px;
}
.btn-4{margin-left: 40px;}
.btn-4 input{background: none;border: 0;line-height: 45px;font-size: 20px;outline: none;}
.btn:hover {
text-decoration: none;
}
.btn-1 {
font-weight: 100;
margin-top: 0px;
}
.btn-1 svg {
height: 45px;
left: 0;
position: absolute;
top: 0;
width: 100%;
}
.btn-1 rect {
fill: none;
stroke: blue;
stroke-width: 2;
stroke-dasharray: 422, 0;
}
.btn-1:hover {
background: rgba(225, 51, 45, 0);
font-weight: 900;
letter-spacing: 1px;
}
.btn-1:hover rect {
stroke-width: 5;
stroke-dasharray: 15, 310;
stroke-dashoffset: 48;
-webkit-transition: all 1.35s cubic-bezier(0.19, 1, 0.22, 1);
transition: all 1.35s cubic-bezier(0.19, 1, 0.22, 1);
}
.btn-2 {
letter-spacing: 0;
}
.btn-2:hover,
.btn-2:active {
letter-spacing: 5px;
}
.btn-2:after,
.btn-2:before {
-webkit-backface-visibility: hidden;
backface-visibility: hidden;
border: 1px solid rgba(255, 255, 255, 0);
bottom: 0px;
content: " ";
display: block;
margin: 0 auto;
position: relative;
-webkit-transition: all 280ms ease-in-out;
transition: all 280ms ease-in-out;
width: 0;
}
.btn-2:hover:after,
.btn-2:hover:before {
-webkit-backface-visibility: hidden;
backface-visibility: hidden;
border-color: #fff;
-webkit-transition: width 350ms ease-in-out;
transition: width 350ms ease-in-out;
width: 70%;
}
.btn-2:hover:before {
bottom: auto;
top: 0;
width: 70%;
}
.btn-3 {
background: #e3403a;
border: 1px solid #da251f;
box-shadow: 0px 2px 0 #d6251f, 2px 4px 6px #e02a24;
font-weight: 900;
letter-spacing: 1px;
-webkit-transition: all 150ms linear;
transition: all 150ms linear;
}
.btn-3:hover {
background: #e02c26;
border: 1px solid rgba(0, 0, 0, 0.05);
box-shadow: 1px 1px 2px rgba(255, 255, 255, 0.2);
color: #ec817d;
text-decoration: none;
text-shadow: -1px -1px 0 #c2211c;
-webkit-transition: all 250ms linear;
transition: all 250ms linear;
}
.btn-4 {
border: 1px solid blue;
overflow: hidden;
position: relative;
}
.btn-4 span {
z-index: 20;
}
.btn-4:after {
background: #fff;
content: "";
height: 155px;
left: -75px;
opacity: .8;
position: absolute;
top: -50px;
-webkit-transform: rotate(35deg);
-ms-transform: rotate(35deg);
transform: rotate(35deg);
-webkit-transition: all 550ms cubic-bezier(0.19, 1, 0.22, 1);
transition: all 550ms cubic-bezier(0.19, 1, 0.22, 1);
width: 50px;
z-index: -10;
background: blue;
}
.btn-4:hover:after {
left: 120%;
-webkit-transition: all 550ms cubic-bezier(0.19, 1, 0.22, 1);
transition: all 550ms cubic-bezier(0.19, 1, 0.22, 1);
}