软件学院
课程设计
项 目 文 档
课程设计项目: 购物网站的后台管理
班 级: 软件1307
学 号: 20131613243
姓 名: 刘帅
上课 时间:2015.9. 8——2015.9.18
实训教师 (签名)
辅导教师(签名)
一.实训每日报告
第一天
Jdbc:
Test1:
package com.sun.jdbc;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
public class Test1 {
public static void main(String[] args) throws InstantiationException, IllegalAccessException, ClassNotFoundException, SQLException {
//一个基本JDBC操作步骤
String className = "com.mysql.jdbc.Driver";
String url="jdbc:mysql://127.0.0.1:3306/goodsdb?useUnicode=true&characterEncoding=utf8";
//1 创建数据库连接对象java.sql.Connection他是一个规范。具体的实现是由各数据库厂商提供的。
Class.forName(className).newInstance();//类加载。加载数据库的驱动类。
Connection conn = DriverManager.getConnection(url, "root", "123456") ;
// System.out.println(conn);
//2 操作,发送SQL。需要使用PreparedStatement对象。
String sql ="select * from goods inner join types on goods.goodsType = types.id";
PreparedStatement pstat = conn.prepareStatement(sql);
//如果操作的增删改与查询执行的方法不同
//pstat.executeUpdate();
//3 接收查询结果,接收数据库查询 结果的对象叫结果集对象。rs,二维表格
ResultSet rs = pstat.executeQuery();
while(rs.next()){
System.out.println("商品编号:"+rs.getInt("id"));
System.out.println(rs.getString("goodsName"));
System.out.println(rs.getFloat("goodsPrice"));
System.out.println(rs.getInt("goodsNum"));
System.out.println(rs.getInt("goodsType"));
System.out.println(rs.getString("typeName"));
System.out.println("---------------");
}
//4 关闭
conn.close();
System.out.println("end");
}
}
Test2:
package com.sun.jdbc;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
public class Test2 {
public static void main(String[] args) throws InstantiationException, IllegalAccessException, ClassNotFoundException, SQLException {
//一个基本JDBC操作步骤
String className = "com.mysql.jdbc.Driver";
String url="jdbc:mysql://127.0.0.1:3306/goodsdb?useUnicode=true&characterEncoding=utf8";
//1 创建数据库连接对象java.sql.Connection他是一个规范。具体的实现是由各数据库厂商提供的。
Class.forName(className).newInstance();//类加载。加载数据库的驱动类。
Connection conn = DriverManager.getConnection(url, "root", "123456") ;
// System.out.println(conn);
//2 操作,发送SQL。需要使用PreparedStatement对象。
//在Pstat中可以使用参数。在SQL语句中使用?号占位在
String sql ="insert into goods(goodsName,goodsPrice,goodsNum,goodsType) values(?,?,?,?)";
PreparedStatement pstat = conn.prepareStatement(sql);
//如果操作的增删改与查询执行的方法不同
pstat.setString(1, "手电筒");
pstat.setFloat(2, 15.2f);
pstat.setInt(3, 100);
pstat.setInt(4, 2);
int i = pstat.executeUpdate();
System.out.println("操作影响了"+i+"行");
//4 关闭
conn.close();
System.out.println("end");
}
}
Utils:
package com.sun.utils;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
/**
* 数据库连接的工具类 封装了数据库连接的创建和关闭 的同一个线程中没关闭数据库连接之间获得数据库连接对象都是同一个。
*
* @author Boss
*
*/
public class ConnectionUtils {
//本地线程对象。一个线程中只有一个本地线程对象,本地线程对象中可以存放一个对象。
private static ThreadLocal<Connection> threadLocal = new ThreadLocal<Connection>();
private static final String CLASS_NAME="com.mysql.jdbc.Driver";
private static final String URL = "jdbc:mysql://127.0.0.1:3306/goodsdb?useUnicode=true&characterEncoding=utf8";
static{
try {
// 类加载。加载数据库的驱动类。
Class.forName(CLASS_NAME).newInstance();
} catch (InstantiationException | IllegalAccessException
| ClassNotFoundException e) {
e.printStackTrace();
}
}
public static Connection getConnection() throws SQLException {
Connection conn = threadLocal.get();//先从本地线程对象取数据库连接对象
if(conn == null || conn.isClosed()){//如果本地线程中没有连接对象
//创建连接
System.out.println("创建数据库连接!");
conn = DriverManager.getConnection(URL, "root", "123456");
//将连接放到本地线程
threadLocal.set(conn);
}
return conn;
}
public static void closeConnection(){
try {
Connection conn = getConnection();
if(conn != null && !conn.isClosed()){
conn.close();
}
} catch (SQLException e) {
e.printStackTrace();
}finally{
threadLocal.set(null);
}
}
}
Test:
package com.test;
import java.sql.SQLException;
import com.sun.utils.ConnectionUtils;
public class Test {
public static void main(String[] args) throws SQLException {
// TODO Auto-generated method stub
System.out.println(ConnectionUtils.getConnection());
System.out.println(ConnectionUtils.getConnection());
ConnectionUtils.closeConnection();
System.out.println(ConnectionUtils.getConnection());
}
}
第二天
DBCP
Test:
package com.test;
import java.sql.Connection;
import com.utils.ConnectionUtils;
public class Test {
public static void main(String[] args) throws Exception {
// TODO Auto-generated method stub
Connection conn = ConnectionUtils.getConnection();
System.out.println(conn);
ConnectionUtils.closeConnection();
}
}
Utils:
package com.utils;
import java.io.IOException;
import java.io.InputStream;
import java.sql.Connection;
import java.sql.SQLException;
import java.util.Properties;
import javax.sql.DataSource;
import org.apache.commons.dbcp.BasicDataSourceFactory;
/**
* 在这个类中连接对象的管理 1 获取连接对象 2 释放连接对象
*
* @author Boss
*/
public class ConnectionUtils {
// 加载资源文件的内容
private static Properties properties = new Properties();// 加载资源文件的对象
static {
// is对象是一个输入流对象
try {
// is对象负责连接jdbc.properties文件
InputStream is = ConnectionUtils.class
.getResourceAsStream("/jdbc.properties");
// 将资源文件的内容加载到properties对象中
properties.load(is);
// 关闭is流对象
is.close();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}// 加载资源文件
}
private static Connection conn = null;
/**
* 获取数据库连接的方法
* @return 数据库连接对象
* @throws Exception
*/
public static Connection getConnection() throws Exception {
// 连接的创建是有条件的?连接不存在,或连接已经关闭
if (conn == null || conn.isClosed()) {
// ds是数据源对象。在这个对象中管理和维护了大量数据库连接对象
DataSource ds = BasicDataSourceFactory.createDataSource(properties);
conn = ds.getConnection();
}
return conn;
}
/**
* 释放数据库连接的方法
*/
public static void closeConnection() {
try {
if (conn != null && !conn.isClosed()) {
conn.close();
}
} catch (SQLException e) {
e.printStackTrace();
}
}
}
Webroot:
<%@page import="java.text.SimpleDateFormat"%>
<%@ 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>
This is my JSP page. <br>
系统当前时间:
<%
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss");
Date date = new Date();
String str = sdf.format(date);
out.println(str);
%>
</body>
</html>
第三天
Com.dao
goodsDAO:
package com.dao;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.util.ArrayList;
import java.util.List;
import com.domain.Goods;
import com.domain.Types;
import com.utils.ConnectionUtils;
/**
* 封装针对Goods表CURD的操作
*
* @author Boss
*
*/
public class GoodsDAO {
/**
* 查询所有商品的方法
*
* @return 所有商品信息的集合对象
* @throws Exception
*/
public List<Goods> findAll() throws Exception {
try {
List<Goods> goodsList = new ArrayList<Goods>();
Connection conn = ConnectionUtils.getConnection();
String sql = "select * from goods inner join types on goods.goodsType = types.id";
PreparedStatement pstat = conn.prepareStatement(sql);
ResultSet rs = pstat.executeQuery();
while (rs.next()) {
Goods goods = new Goods();
goods.setId(rs.getInt("id"));
goods.setGoodsName(rs.getString("goodsName"));
goods.setGoodsPrice(rs.getFloat("goodsPrice"));
goods.setGoodsNum(rs.getInt("goodsNum"));
Types types = new Types();
types.setId(rs.getInt("goodsType"));
types.setTypeName(rs.getString("typeName"));
goods.setTypes(types);
goodsList.add(goods);
}
return goodsList;
} finally {
ConnectionUtils.closeConnection();
}
}
}
Com.domain:
Goods:
package com.domain;
/**
* 封装goods表的数据的对象
* @author Boss
*
*/
public class Goods {
private int id;
private String goodsName;
private float goodsPrice;
private int goodsNum;
private Types types;//对应商品的类型
public Goods() {
// TODO Auto-generated constructor stub
}
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public String getGoodsName() {
return goodsName;
}
public void setGoodsName(String goodsName) {
this.goodsName = goodsName;
}
public float getGoodsPrice() {
return goodsPrice;
}
public void setGoodsPrice(float goodsPrice) {
this.goodsPrice = goodsPrice;
}
public int getGoodsNum() {
return goodsNum;
}
public void setGoodsNum(int goodsNum) {
this.goodsNum = goodsNum;
}
public Types getTypes() {
return types;
}
public void setTypes(Types types) {
this.types = types;
}
}
Types:
package com.domain;
/**
* 封装数据库中types表中内容的对象
* @author Boss
*/
public class Types {
private int id;
private String typeName;
public Types() {
}
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public String getTypeName() {
return typeName;
}
public void setTypeName(String typeName) {
this.typeName = typeName;
}
}
Webroot:
Index:
<%@ 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>
<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>
This is my JSP page. <br>
<table border="1" width="60%" cellpadding="2" cellspacing="0">
<tr>
<th>a</th>
<th>b</th>
</tr>
<tr>
<td>1</td>
<td>2</td>
</tr>
<tr>
<td>1</td>
<td>2</td>
</tr>
</table>
</body>
</html>
Show01:
<%@page import="java.sql.ResultSet"%>
<%@page import="java.sql.PreparedStatement"%>
<%@page import="com.utils.ConnectionUtils"%>
<%@page import="java.sql.Connection"%>
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>显示所有商品的第一版</title>
</head>
<body>
<%
Connection conn = ConnectionUtils.getConnection();
String sql = "select * from goods inner join types on goods.goodsType = types.id";
PreparedStatement pstat = conn.prepareStatement(sql);
ResultSet rs = pstat.executeQuery();
while (rs.next()) {
%>
<%= rs.getInt("id") %> <br>
<%= rs.getString("goodsName") %> <br>
<%= rs.getString("typeName") %> <br>
<hr>
<% }
ConnectionUtils.closeConnection(); %>
</body>
</html>
Show02:
<%@page import="java.sql.ResultSet"%>
<%@page import="java.sql.PreparedStatement"%>
<%@page import="com.utils.ConnectionUtils"%>
<%@page import="java.sql.Connection"%>
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>显示所有商品的第二版-使用表格显示数据</title>
</head>
<body>
<table border="1" width="60%" cellpadding="2" cellspacing="0">
<tr>
<th>商品编号</th>
<th>商品名称</th>
<th>商品类型</th>
</tr>
<%
Connection conn = ConnectionUtils.getConnection();
String sql = "select * from goods inner join types on goods.goodsType = types.id";
PreparedStatement pstat = conn.prepareStatement(sql);
ResultSet rs = pstat.executeQuery();
while (rs.next()) {
%>
<tr>
<td><%=rs.getInt("id")%></td>
<td><%=rs.getString("goodsName")%></td>
<td><%=rs.getString("typeName")%></td>
</tr>
<%
}
%>
</table>
<%
ConnectionUtils.closeConnection();
%>
</body>
</html>
Show03:
<%@page import="com.domain.Goods"%>
<%@page import="com.dao.GoodsDAO"%>
<%@page import="java.sql.ResultSet"%>
<%@page import="java.sql.PreparedStatement"%>
<%@page import="com.utils.ConnectionUtils"%>
<%@page import="java.sql.Connection"%>
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>显示所有商品</title>
</head>
<body>
<table border="1" width="60%" cellpadding="2" cellspacing="0">
<tr>
<th>商品编号</th>
<th>商品名称</th>
<th>商品价格</th>
<th>商品数量</th>
<th>商品类型</th>
</tr>
<%
GoodsDAO goodsDAO = new GoodsDAO();
List<Goods> goodsList = goodsDAO.findAll();
for (Goods goods : goodsList) { %>
<tr>
<td><%=goods.getId()%></td>
<td><%=goods.getGoodsName()%></td>
<td><%=goods.getGoodsPrice()%></td>
<td><%=goods.getGoodsNum()%></td>
<td><%=goods.getTypes().getTypeName()%></td>
</tr>
<%
}
%>
</table>
</body>
</html>
第四天
Com.dao:
GoodsDAO:
package com.dao;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.util.ArrayList;
import java.util.List;
import com.domain.Goods;
import com.domain.Types;
import com.utils.ConnectionUtils;
/**
* 封装针对Goods表CURD的操作
*
* @author Boss
*
*/
public class GoodsDAO {
/**
* 按商品名称查询
*
* @param goodsName
* 商品名称
* @return 查询到的商品对象,如果商品不存在返回null
* @throws Exception
*/
public Goods findByGoodsName(String goodsName) throws Exception {
try {
Connection conn = ConnectionUtils.getConnection();
String sql = "select * from goods inner join types on goods.goodsType = types.id where goodsName = ?";
PreparedStatement pstat = conn.prepareStatement(sql);
pstat.setString(1, goodsName);
ResultSet rs = pstat.executeQuery();
if (rs.next()) {
Goods goods = new Goods();
goods.setId(rs.getInt("id"));
goods.setGoodsName(rs.getString("goodsName"));
goods.setGoodsPrice(rs.getFloat("goodsPrice"));
goods.setGoodsNum(rs.getInt("goodsNum"));
goods.setGoodsStatus(rs.getInt("goodsStatus"));
Types types = new Types();
types.setId(rs.getInt("goodsType"));
types.setTypeName(rs.getString("typeName"));
goods.setTypes(types);
return goods;
} else {
return null;
}
} finally {
ConnectionUtils.closeConnection();
}
}
/**
* 保存新商品
*
* @param goods
* 要保存的新商品对象
* @return true表示保存成功
* @throws Exception
*/
public boolean save(Goods goods) throws Exception {
try {
Connection conn = ConnectionUtils.getConnection();
String sql = "insert into goods(goodsName,goodsPrice,goodsNum,goodsStatus,goodsType) values(?,?,?,?,?)";
PreparedStatement pstat = conn.prepareStatement(sql);
pstat.setString(1, goods.getGoodsName());
pstat.setFloat(2, goods.getGoodsPrice());
pstat.setInt(3, goods.getGoodsNum());
pstat.setInt(4, goods.getGoodsStatus());
pstat.setInt(5, goods.getTypes().getId());
pstat.executeUpdate();
return true;
}finally {
ConnectionUtils.closeConnection();
}
}
/**
* 查询所有商品的方法
*
* @return 所有商品信息的集合对象
* @throws Exception
*/
public List<Goods> findAll() throws Exception {
try {
List<Goods> goodsList = new ArrayList<Goods>();
Connection conn = ConnectionUtils.getConnection();
String sql = "select * from goods inner join types on goods.goodsType = types.id order by goodsPrice desc";
PreparedStatement pstat = conn.prepareStatement(sql);
ResultSet rs = pstat.executeQuery();
while (rs.next()) {
Goods goods = new Goods();
goods.setId(rs.getInt("id"));
goods.setGoodsName(rs.getString("goodsName"));
goods.setGoodsPrice(rs.getFloat("goodsPrice"));
goods.setGoodsNum(rs.getInt("goodsNum"));
goods.setGoodsStatus(rs.getInt("goodsStatus"));
Types types = new Types();
types.setId(rs.getInt("goodsType"));
types.setTypeName(rs.getString("typeName"));
goods.setTypes(types);
goodsList.add(goods);
}
return goodsList;
} finally {
ConnectionUtils.closeConnection();
}
}
}
typesDAO:
package com.dao;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.util.ArrayList;
import java.util.List;
import com.domain.Types;
import com.utils.ConnectionUtils;
public class TypesDAO {
public List<Types> findAll() throws Exception{
try {
List<Types> typesList = new ArrayList<Types>();
Connection conn = ConnectionUtils.getConnection();
String sql = "select * from types";
PreparedStatement pstat = conn.prepareStatement(sql);
ResultSet rs = pstat.executeQuery();
while (rs.next()) {
Types types = new Types();
types.setId(rs.getInt("id"));
types.setTypeName(rs.getString("typeName"));
typesList.add(types);
}
return typesList;
} finally {
ConnectionUtils.closeConnection();
}
}
}
Com.domain:
Goods:
package com.domain;
/**
* 封装goods表的数据的对象
* @author Boss
*
*/
public class Goods {
private int id;
private String goodsName;
private float goodsPrice;
private int goodsNum;
private int goodsStatus;
public int getGoodsStatus() {
return goodsStatus;
}
public void setGoodsStatus(int goodsStatus) {
this.goodsStatus = goodsStatus;
}
private Types types;//对应商品的类型
public Goods() {
// TODO Auto-generated constructor stub
}
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public String getGoodsName() {
return goodsName;
}
public void setGoodsName(String goodsName) {
this.goodsName = goodsName;
}
public float getGoodsPrice() {
return goodsPrice;
}
public void setGoodsPrice(float goodsPrice) {
this.goodsPrice = goodsPrice;
}
public int getGoodsNum() {
return goodsNum;
}
public void setGoodsNum(int goodsNum) {
this.goodsNum = goodsNum;
}
public Types getTypes() {
return types;
}
public void setTypes(Types types) {
this.types = types;
}
}
Types:
package com.domain;
/**
* 封装数据库中types表中内容的对象
* @author Boss
*/
public class Types {
private int id;
private String typeName;
public Types() {
}
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public String getTypeName() {
return typeName;
}
public void setTypeName(String typeName) {
this.typeName = typeName;
}
}
Test:
Savetest:
package com.test;
import com.dao.GoodsDAO;
import com.domain.Goods;
import com.domain.Types;
public class SaveTest {
public static void main(String[] args) throws Exception {
// TODO Auto-generated method stub
Goods goods = new Goods();
goods.setGoodsName("皮鞋");
goods.setGoodsNum(10);
goods.setGoodsPrice(200);
goods.setGoodsStatus(1);
Types types = new Types();
types.setId(5);
goods.setTypes(types);
GoodsDAO goodsDAO = new GoodsDAO();
if( goodsDAO.findByGoodsName(goods.getGoodsName() ) == null ){
if( goodsDAO.save(goods) ){
System.out.println("保存成功!");
}else{
System.out.println("保存失败!");
}
}else{
System.out.println("商品名称已经使用,保存失败!");
}
}
}
Webroot:
Dosave:
<%@page import="com.dao.GoodsDAO"%>
<%@page import="com.domain.Types"%>
<%@page import="com.domain.Goods"%>
<%@ 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 'dosave.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>
<%
request.setCharacterEncoding("utf-8");//设置请求的中文编码。与JSP页面使用的编码一致。
String goodsName = request.getParameter("goodsName");
float goodsPrice = Float.parseFloat(request
.getParameter("goodsPrice"));
int goodsNum = Integer.parseInt(request.getParameter("goodsNum"));
int goodsStatus = Integer.parseInt(request
.getParameter("goodsStatus"));
int typesId = Integer.parseInt(request.getParameter("typesId"));
Goods goods = new Goods();
goods.setGoodsName(goodsName);
goods.setGoodsNum(goodsNum);
goods.setGoodsPrice(goodsPrice);
goods.setGoodsStatus(goodsStatus);
Types types = new Types();
types.setId(typesId);
goods.setTypes(types);
GoodsDAO goodsDAO = new GoodsDAO();
if (goodsDAO.findByGoodsName(goods.getGoodsName()) == null) {
if (goodsDAO.save(goods)) {
%>
保存成功!恭喜。如果没有自动跳转请点<a href="/web/show.jsp">这里</a>!
<%
} else {
out.println("保存失败!");
}
} else {
out.println("商品名称已经使用,保存失败!");
}
%>
</body>
</html>
Save:
<%@page import="com.domain.Types"%>
<%@page import="com.dao.TypesDAO"%>
<%@ 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 'save.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>
<form action="/web/dosave.jsp" method="post">
商品名称:<input type="text" name="goodsName"><br>
商品价格:<input type="text" name="goodsPrice"><br>
商品数量:<input type="text" name="goodsNum"><br>
商品状态:<input type="radio" name="goodsStatus" value="1">上架<input type="radio" name="goodsStatus" value="0">下架<br>
商品类型:<select name="typesId">
<%
TypesDAO typesDAO = new TypesDAO();
List<Types> typesList = typesDAO.findAll();
for(Types types : typesList){
%>
<option value="<%=types.getId() %>"><%=types.getTypeName() %></option>
<%} %>
</select>
<br>
<input type="submit" value="提交"><input type="reset" value="重置">
</form>
</body>
</html>
Show:
<%@page import="com.domain.Goods"%>
<%@page import="com.dao.GoodsDAO"%>
<%@ 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 'show.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">
-->
<style type="text/css">
<!--
body {
margin-left: 0px;
margin-top: 0px;
margin-right: 0px;
margin-bottom: 0px;
}
.STYLE1 {font-size: 12px}
.STYLE3 {font-size: 12px; font-weight: bold; }
.STYLE4 {
color: #03515d;
font-size: 12px;
}
-->
</style>
<script>
var highlightcolor='#c1ebff';
//此处clickcolor只能用win系统颜色代码才能成功,如果用#xxxxxx的代码就不行,还没搞清楚为什么:(
var clickcolor='#51b2f6';
function changeto(){
source=event.srcElement;
if (source.tagName=="TR"||source.tagName=="TABLE")
return;
while(source.tagName!="TD")
source=source.parentElement;
source=source.parentElement;
cs = source.children;
//alert(cs.length);
if (cs[1].style.backgroundColor!=highlightcolor&&source.id!="nc"&&cs[1].style.backgroundColor!=clickcolor)
for(i=0;i<cs.length;i++){
cs[i].style.backgroundColor=highlightcolor;
}
}
function changeback(){
if (event.fromElement.contains(event.toElement)||source.contains(event.toElement)||source.id=="nc")
return
if (event.toElement!=source&&cs[1].style.backgroundColor!=clickcolor)
//source.style.backgroundColor=originalcolor
for(i=0;i<cs.length;i++){
cs[i].style.backgroundColor="";
}
}
function clickto(){
source=event.srcElement;
if (source.tagName=="TR"||source.tagName=="TABLE")
return;
while(source.tagName!="TD")
source=source.parentElement;
source=source.parentElement;
cs = source.children;
//alert(cs.length);
if (cs[1].style.backgroundColor!=clickcolor&&source.id!="nc")
for(i=0;i<cs.length;i++){
cs[i].style.backgroundColor=clickcolor;
}
else
for(i=0;i<cs.length;i++){
cs[i].style.backgroundColor="";
}
}
</script>
</head>
<body>
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td height="30" background="images/tab_05.gif"><table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td width="12" height="30"><img src="images/tab_03.gif" width="12" height="30" /></td>
<td><table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td width="46%" valign="middle"><table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td width="5%"><div align="center"><img src="images/tb.gif" width="16" height="16" /></div></td>
<td width="95%" class="STYLE1"><span class="STYLE3">你当前的位置</span>:[基础数据管理]-[商品管理]-[查询商品]</td>
</tr>
</table></td>
<td width="54%"><table border="0" align="right" cellpadding="0" cellspacing="0">
<tr>
<td width="60"><table width="90%" border="0" cellpadding="0" cellspacing="0">
<tr>
<td class="STYLE1"><div align="center"><img src="images/22.gif" width="14" height="14" /></div></td>
<td class="STYLE1"><div align="center"><a href="/web/save.jsp">新增</a></div></td>
</tr>
</table></td>
<td width="52"><table width="88%" border="0" cellpadding="0" cellspacing="0">
<tr>
<td class="STYLE1"><div align="center"><img src="images/11.gif" width="14" height="14" /></div></td>
<td class="STYLE1"><div align="center">删除</div></td>
</tr>
</table></td>
</tr>
</table></td>
</tr>
</table></td>
<td width="16"><img src="images/tab_07.gif" width="16" height="30" /></td>
</tr>
</table></td>
</tr>
<tr>
<td><table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td width="8" background="images/tab_12.gif"> </td>
<td><table width="100%" border="0" cellpadding="0" cellspacing="1" bgcolor="b5d6e6" onmouseover="changeto()" onmouseout="changeback()">
<tr>
<td width="3%" height="22" background="images/bg.gif" bgcolor="#FFFFFF"><div align="center">
<input type="checkbox" name="ids" value="" id="goodsIds" />
</div></td>
<td width="10%" height="22" background="images/bg.gif" bgcolor="#FFFFFF"><div align="center"><span class="STYLE1">商品编号</span></div></td>
<td width="15%" height="22" background="images/bg.gif" bgcolor="#FFFFFF"><div align="center"><span class="STYLE1">商品名称</span></div></td>
<td width="15%" height="22" background="images/bg.gif" bgcolor="#FFFFFF"><div align="center"><span class="STYLE1">商品价格</span></div></td>
<td width="15%" height="22" background="images/bg.gif" bgcolor="#FFFFFF"><div align="center"><span class="STYLE1">商品数量</span></div></td>
<td width="15%" height="22" background="images/bg.gif" bgcolor="#FFFFFF"><div align="center"><span class="STYLE1">商品类型</span></div></td>
<td width="10%" height="22" background="images/bg.gif" bgcolor="#FFFFFF"><div align="center"><span class="STYLE1">商品状态</span></div></td>
<td width="15%" height="22" background="images/bg.gif" bgcolor="#FFFFFF"><div align="center"><span class="STYLE1">基本操作</span></div></td>
</tr>
<!-- 数据显示区域 -->
<%
GoodsDAO goodsDAO = new GoodsDAO();
List<Goods> goodsList = goodsDAO.findAll();
for (Goods goods : goodsList) {
%>
<tr>
<td height="20" bgcolor="#FFFFFF"><div align="center">
<input type="checkbox" name="goodsId" value="" />
</div></td>
<td height="20" bgcolor="#FFFFFF"><div align="center">
<span class="STYLE1"><%=goods.getId()%></span></div></td>
<td height="20" bgcolor="#FFFFFF"><div align="center">
<span class="STYLE1"><%=goods.getGoodsName()%></span></div></td>
<td height="20" bgcolor="#FFFFFF"><div align="center">
<span class="STYLE1"><%=goods.getGoodsPrice()%></span></div></td>
<td height="20" bgcolor="#FFFFFF"><div align="center">
<span class="STYLE1"><%=goods.getGoodsNum()%></span></div></td>
<td height="20" bgcolor="#FFFFFF"><div align="center">
<span class="STYLE1"><%=goods.getTypes().getTypeName()%></span></div></td>
<td height="20" bgcolor="#FFFFFF"><div align="center">
<span class="STYLE1"><%=goods.getGoodsStatus()==1?"上架":"下架" %></span></div></td>
<td height="20" bgcolor="#FFFFFF"><div align="center">
<span class="STYLE4">
<img src="images/edt.gif" width="16" height="16" /><a href="">编辑</a>
<img src="images/del.gif" width="16" height="16" /><a href="">删除</a></span></div></td>
</tr>
<%} %>
<!-- 数据显示区域结束 -->
</table></td>
<td width="8" background="images/tab_15.gif"> </td>
</tr>
</table></td>
</tr>
<tr>
<td height="35" background="images/tab_19.gif"><table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td width="12" height="35"><img src="images/tab_18.gif" width="12" height="35" /></td>
<td><table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td class="STYLE4"> 共有 120 条记录,当前第 1/10 页</td>
<td><table border="0" align="right" cellpadding="0" cellspacing="0">
<tr>
<td width="40"><img src="images/first.gif" width="37" height="15" /></td>
<td width="45"><img src="images/back.gif" width="43" height="15" /></td>
<td width="45"><img src="images/next.gif" width="43" height="15" /></td>
<td width="40"><img src="images/last.gif" width="37" height="15" /></td>
<td width="100"><div align="center"><span class="STYLE1">转到第<input name="textfield" type="text" size="4" style="height:12px; width:20px; border:1px solid #999999;" />
页 </span></div></td>
<td width="40"><img src="images/go.gif" width="37" height="15" /></td>
</tr>
</table></td>
</tr>
</table></td>
<td width="16"><img src="images/tab_20.gif" width="16" height="35" /></td>
</tr>
</table></td>
</tr>
</table>
</body>
</html>
第五天
Webroot:
Doupdate:
<%@page import="com.dao.GoodsDAO"%>
<%@page import="com.domain.Goods"%>
<%@page import="com.domain.Types"%>
<%@ 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 'dosave.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>
<%
request.setCharacterEncoding("utf-8");//设置请求的中文编码,与JSP页面的编码一致。
String goodsName = request.getParameter("goodsName");
float goodsPrice = Float.parseFloat(request .getParameter("goodsPrice"));
int goodsNum = Integer.parseInt(request.getParameter("goodsNum"));
int goodsStatus = Integer.parseInt(request.getParameter("goodsStatus"));
int typesId = Integer.parseInt(request.getParameter("typesId"));
int goodsId = Integer.parseInt(request.getParameter("goodsId"));//补
String oldGoodsName = request.getParameter("oldGoodsName");//补
Goods goods = new Goods();
goods.setId(goodsId);//补
goods.setGoodsName(goodsName);
goods.setGoodsNum(goodsNum);
goods.setGoodsPrice(goodsPrice);
goods.setGoodsStatus(goodsStatus);
Types types = new Types();
types.setId(typesId);
goods.setTypes(types);
GoodsDAO goodsDAO = new GoodsDAO();
boolean bool = false;//保存更新是否成功的变量
//判断商品名称是否经过修改?
if(oldGoodsName.equals(goodsName)){
bool = goodsDAO.update(goods);
}else{
if (goodsDAO.findByGoodsName(goods.getGoodsName()) == null) {
bool = goodsDAO.update(goods);
}else{
out.print("商品名称已经存在!");
bool = false;
}
}
if(bool){
//自动页面导航。
response.sendRedirect("/web/show.jsp");
}else{
%>
更新失败!请点<a href="/web/update.jsp?goodsId=<%=goodsId%>">这里</a>重新修改!
<%
}
%>
</body>
</html>
Update:
<%@page import="com.domain.Goods"%>
<%@page import="com.dao.GoodsDAO"%>
<%@page import="com.domain.Types"%>
<%@page import="com.dao.TypesDAO"%>
<%@ 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 'save.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>
<%
int goodsId = Integer.parseInt(request.getParameter("goodsId"));
GoodsDAO goodsDAO = new GoodsDAO();
Goods goods = goodsDAO.findById(goodsId);
%>
<form action="/web/doupdate.jsp" method="post">
<input type="hidden" name="goodsId" value="<%=goods.getId() %>">
<input type="hidden" name="oldGoodsName" value="<%=goods.getGoodsName() %>">
商品名称:<input type="text" name="goodsName" value="<%=goods.getGoodsName() %>"><br>
商品价格:<input type="text" name="goodsPrice" value="<%=goods.getGoodsPrice()%>"><br>
商品数量:<input type="text" name="goodsNum" value="<%=goods.getGoodsNum()%>"><br>
商品状态:<input type="radio" name="goodsStatus" value="1" <%= goods.getGoodsStatus()==1?"checked":"" %> >上架
<input type="radio" name="goodsStatus" value="0" <%= goods.getGoodsStatus()==0?"checked":"" %> >下架<br>
商品类型:<select name="typesId">
<%
TypesDAO typesDAO = new TypesDAO();
List<Types> typesList = typesDAO.findAll();
for(Types types :typesList ){
%>
<option value="<%=types.getId()%>" <%= types.getId()==goods.getTypes().getId()?"selected":"" %> >
<%= types.getTypeName() %>
</option>
<% } %>
</select>
<br>
<input type="submit" value="提交">
<input type="reset" value="重置">
</form>
</body>
</html>
第六天
Webroot:
Checkbox:
<%@ 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 'checkbox.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">
function changeCheckBox() {
var goodsIds = document.getElementById("goodsIds");
var goodsIdList = document.getElementsByName("goodsId");
for(i =0 ;i<goodsIdList.length ; i++){
goodsIdList[i].checked = goodsIds.checked;
}
}
</script>
</head>
<body>
<input type="checkbox" id="goodsIds" onclick="changeCheckBox()">
<br>
<hr>
<input type="checkbox" name="goodsId" value="1">
<br>
<input type="checkbox" name="goodsId" value="2">
<br>
<input type="checkbox" name="goodsId">
<br>
<input type="checkbox" name="goodsId">
<br>
<input type="checkbox" name="goodsId">
<br>
<input type="checkbox" name="goodsId">
<br>
</body>
</html>
Dodelete:
<%@page import="com.dao.GoodsDAO"%>
<%@page import="com.domain.Goods"%>
<%@page import="com.domain.Types"%>
<%@ 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 'dosave.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>
<%
request.setCharacterEncoding("utf-8");//设置请求的中文编码,与JSP页面的编码一致
int goodsId = Integer.parseInt(request.getParameter("goodsId"));
GoodsDAO goodsDAO = new GoodsDAO();
if(goodsDAO.delete(goodsId)){
response.sendRedirect("/web/show.jsp");
}else{
%>
删除失败!<a href="/web/show.jsp">这里</a>!
<%
}
%>
</body>
</html>
Dodeletes:
<%@page import="com.dao.GoodsDAO"%>
<%@ 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 'dodeletes.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>
<%
String[] goodsIds = request.getParameterValues("goodsId");
GoodsDAO goodsDAO = new GoodsDAO();
for(String goodsId : goodsIds){
goodsDAO.delete(Integer.parseInt(goodsId));
}
response.sendRedirect("/web/show.jsp");
%>
</body>
</html>
第七天
MD5
MD5_Encoding:
package coms;
import java.lang.*;
import java.math.*;
/*******************************************************************************
*
*
* MD5数据加密类
*/
public class MD5_Encoding {
// RFC1321中定义的标准4*4矩阵的常量定义。
static final int S11 = 7,S12 = 12,S13 = 17, S14 = 22;
static final int S21 = 5,S22 = 9, S23 = 14, S24 = 20;
static final int S31 = 4,S32 = 11,S33 = 16, S34 = 23;
static final int S41 = 4 ,S42 = 10,S43 = 15, S44 = 21;
// 按RFC1321标准定义不可变byte型数组PADDING
static final byte[] PADDING = { -128, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0 };
// MD5计算过程中的3组核心数据,采用数组形式存放
private long[] state = new long[4]; // 计算状态(分别对应a b c d)
private byte[] buffer = new byte[64]; // 分配64个字节私有缓冲区
private long[] count = new long[2]; // 位个数
// 最新一次计算结果的16进制ASCII字符串表示,代表了16个字符串形式的MD5值
public String resultStr;
// 最新一次计算结果的2进制数组表示,一共16个字节,代表了128bit形式的MD5值
public byte[] digest = new byte[16];
// MD5_Encoding类提供的主要的接口函数getMD5ofStr,用来进行数据加密变换。调用其可对任意字符串进行加密运算,并以字符串形式返回加密结果。
public String getMD5ofStr(String in) {
md5Init(); // 初始化
md5Update(in.getBytes(), in.length());// 调用MD5的主计算过程
md5Final(); // 输出结果到digest数组中
for (int i = 0; i < 16; i++) {
resultStr += byteToHEX(digest[i]); // 将digest数组中的每个byte型数据转为16进制形式的字符串
}
return resultStr;
}
// 标准的构造函数,调用md5Init函数进行初始化工作
public MD5_Encoding() {
md5Init();
return;
}
// md5初始化函数.初始化核心变量.
private void md5Init() {
state[0] = 0x67452301L; // 定义state为RFC1321中定义的标准幻数
state[1] = 0xefcdab89L; // 定义state为RFC1321中定义的标准幻数
state[2] = 0x98badcfeL; // 定义state为RFC1321中定义的标准幻数
state[3] = 0x10325476L; // 定义state为RFC1321中定义的标准幻数
count[0] = count[1] =0L; // 初始化为0
resultStr = "";// 初始化resultStr字符串为空
for(int i=0;i<16;i++) digest[i]=0;//初始化digest数组元素为0
return;
}
//定义F G H I 为4个基数 ,即为4个基本的MD5函数,进行简单的位运算
private long F(long x, long y, long z) {
return (x & y) | ((~x) & z);
}
private long G(long x, long y, long z) {
return (x & z) | (y & (~z));
}
private long H(long x, long y, long z) {
return x ^ y ^ z;
}
private long I(long x, long y, long z) {
return y ^ (x | (~z));
}
// FF,GG,HH和II调用F,G,H,I函数进行进一步变换
private long FF(long a, long b, long c, long d, long x, long s, long ac) {
a += F(b, c, d) + x + ac;
a = ((int) a << s) | ((int) a >>> (32 - s)); //这里long型数据右移时使用无符号右移运算符>>>
a += b;
return a;
}
private long GG(long a, long b, long c, long d, long x, long s, long ac) {
a += G(b, c, d) + x + ac;
a = ((int) a << s) | ((int) a >>> (32 - s)); //这里long型数据右移时使用无符号右移运算符>>>
a += b;
return a;
}
private long HH(long a, long b, long c, long d, long x, long s, long ac) {
a += H(b, c, d) + x + ac;
a = ((int) a << s) | ((int) a >>> (32 - s));//这里long型数据右移时使用无符号右移运算符>>>
a += b;
return a;
}
private long II(long a, long b, long c, long d, long x, long s, long ac) {
a += I(b, c, d) + x + ac;
a = ((int) a << s) | ((int) a >>> (32 - s));//这里long型数据右移时使用无符号右移运算符>>>
a += b;
return a;
}
// MD5的主计算过程,input是需要变换的二进制字节串,inputlen是长度
private void md5Update(byte[] input, int inputLen) {
int i=0, index, partLen;
byte[] block = new byte[64]; // 分配64个字节缓冲区
//根据count计算index值。这里long型数据右移时使用无符号右移运算符>>>
index = (int) (count[0] >>> 3) & 0x3F;
if ((count[0] += (inputLen << 3)) < (inputLen << 3))
count[1]++;
count[1] += (inputLen >>> 29); //这里int型数据右移时使用无符号右移运算符>>>
partLen = 64 - index; //计算partLen值
if (inputLen >= partLen) {
md5Memcpy(buffer, input, index, 0, partLen);
md5Transform(buffer);
for (i = partLen; i + 63 < inputLen; i += 64) {
md5Memcpy(block, input, 0, i, 64);
md5Transform(block);
}
index = 0;
} else
i = 0;
md5Memcpy(buffer, input, index, i, inputLen - i);
}
// 整理和填写输出结果,结果放到数组digest中。
private void md5Final() {
byte[] bits = new byte[8];
int index, padLen;
Encode(bits, count, 8);
index = (int) (count[0] >>> 3) & 0x3f; //这里long型数据右移时使用无符号右移运算符>>>
padLen = (index < 56) ? (56 - index) : (120 - index);
md5Update(PADDING, padLen);
md5Update(bits, 8);
Encode(digest, state, 16);
}
// byte数组的块拷贝函数,将input数组中的起始位置为inpos,长度len的数据拷贝到output数组起始位置outpos处。
private void md5Memcpy(byte[] output, byte[] input, int outpos, int inpos,
int len) {
int i;
for (i = 0; i < len; i++)
output[outpos + i] = input[inpos + i];
}
// MD5核心变换计算程序,由md5Update函数调用,block是分块的原始字节数组
private void md5Transform(byte block[]) {
long a = state[0], b = state[1], c = state[2], d = state[3];
long[] x = new long[16];
Decode(x, block, 64);
// 进行4级级联运算
// 第1级
a = FF(a, b, c, d, x[0], S11, 0xd76aa478L); /* 1 */
d = FF(d, a, b, c, x[1], S12, 0xe8c7b756L); /* 2 */
c = FF(c, d, a, b, x[2], S13, 0x242070dbL); /* 3 */
b = FF(b, c, d, a, x[3], S14, 0xc1bdceeeL); /* 4 */
a = FF(a, b, c, d, x[4], S11, 0xf57c0fafL); /* 5 */
d = FF(d, a, b, c, x[5], S12, 0x4787c62aL); /* 6 */
c = FF(c, d, a, b, x[6], S13, 0xa8304613L); /* 7 */
b = FF(b, c, d, a, x[7], S14, 0xfd469501L); /* 8 */
a = FF(a, b, c, d, x[8], S11, 0x698098d8L); /* 9 */
d = FF(d, a, b, c, x[9], S12, 0x8b44f7afL); /* 10 */
c = FF(c, d, a, b, x[10], S13, 0xffff5bb1L); /* 11 */
b = FF(b, c, d, a, x[11], S14, 0x895cd7beL); /* 12 */
a = FF(a, b, c, d, x[12], S11, 0x6b901122L); /* 13 */
d = FF(d, a, b, c, x[13], S12, 0xfd987193L); /* 14 */
c = FF(c, d, a, b, x[14], S13, 0xa679438eL); /* 15 */
b = FF(b, c, d, a, x[15], S14, 0x49b40821L); /* 16 */
// 第2级
a = GG(a, b, c, d, x[1], S21, 0xf61e2562L); /* 17 */
d = GG(d, a, b, c, x[6], S22, 0xc040b340L); /* 18 */
c = GG(c, d, a, b, x[11], S23, 0x265e5a51L); /* 19 */
b = GG(b, c, d, a, x[0], S24, 0xe9b6c7aaL); /* 20 */
a = GG(a, b, c, d, x[5], S21, 0xd62f105dL); /* 21 */
d = GG(d, a, b, c, x[10], S22, 0x2441453L); /* 22 */
c = GG(c, d, a, b, x[15], S23, 0xd8a1e681L); /* 23 */
b = GG(b, c, d, a, x[4], S24, 0xe7d3fbc8L); /* 24 */
a = GG(a, b, c, d, x[9], S21, 0x21e1cde6L); /* 25 */
d = GG(d, a, b, c, x[14], S22, 0xc33707d6L); /* 26 */
c = GG(c, d, a, b, x[3], S23, 0xf4d50d87L); /* 27 */
b = GG(b, c, d, a, x[8], S24, 0x455a14edL); /* 28 */
a = GG(a, b, c, d, x[13], S21, 0xa9e3e905L); /* 29 */
d = GG(d, a, b, c, x[2], S22, 0xfcefa3f8L); /* 30 */
c = GG(c, d, a, b, x[7], S23, 0x676f02d9L); /* 31 */
b = GG(b, c, d, a, x[12], S24, 0x8d2a4c8aL); /* 32 */
// 第3级
a = HH(a, b, c, d, x[5], S31, 0xfffa3942L); /* 33 */
d = HH(d, a, b, c, x[8], S32, 0x8771f681L); /* 34 */
c = HH(c, d, a, b, x[11], S33, 0x6d9d6122L); /* 35 */
b = HH(b, c, d, a, x[14], S34, 0xfde5380cL); /* 36 */
a = HH(a, b, c, d, x[1], S31, 0xa4beea44L); /* 37 */
d = HH(d, a, b, c, x[4], S32, 0x4bdecfa9L); /* 38 */
c = HH(c, d, a, b, x[7], S33, 0xf6bb4b60L); /* 39 */
b = HH(b, c, d, a, x[10], S34, 0xbebfbc70L); /* 40 */
a = HH(a, b, c, d, x[13], S31, 0x289b7ec6L); /* 41 */
d = HH(d, a, b, c, x[0], S32, 0xeaa127faL); /* 42 */
c = HH(c, d, a, b, x[3], S33, 0xd4ef3085L); /* 43 */
b = HH(b, c, d, a, x[6], S34, 0x4881d05L); /* 44 */
a = HH(a, b, c, d, x[9], S31, 0xd9d4d039L); /* 45 */
d = HH(d, a, b, c, x[12], S32, 0xe6db99e5L); /* 46 */
c = HH(c, d, a, b, x[15], S33, 0x1fa27cf8L); /* 47 */
b = HH(b, c, d, a, x[2], S34, 0xc4ac5665L); /* 48 */
// 第4级
a = II(a, b, c, d, x[0], S41, 0xf4292244L); /* 49 */
d = II(d, a, b, c, x[7], S42, 0x432aff97L); /* 50 */
c = II(c, d, a, b, x[14], S43, 0xab9423a7L); /* 51 */
b = II(b, c, d, a, x[5], S44, 0xfc93a039L); /* 52 */
a = II(a, b, c, d, x[12], S41, 0x655b59c3L); /* 53 */
d = II(d, a, b, c, x[3], S42, 0x8f0ccc92L); /* 54 */
c = II(c, d, a, b, x[10], S43, 0xffeff47dL); /* 55 */
b = II(b, c, d, a, x[1], S44, 0x85845dd1L); /* 56 */
a = II(a, b, c, d, x[8], S41, 0x6fa87e4fL); /* 57 */
d = II(d, a, b, c, x[15], S42, 0xfe2ce6e0L); /* 58 */
c = II(c, d, a, b, x[6], S43, 0xa3014314L); /* 59 */
b = II(b, c, d, a, x[13], S44, 0x4e0811a1L); /* 60 */
a = II(a, b, c, d, x[4], S41, 0xf7537e82L); /* 61 */
d = II(d, a, b, c, x[11], S42, 0xbd3af235L); /* 62 */
c = II(c, d, a, b, x[2], S43, 0x2ad7d2bbL); /* 63 */
b = II(b, c, d, a, x[9], S44, 0xeb86d391L); /* 64 */
//分别累加到state[0],state[1],state[2],state[3]
state[0] += a;
state[1] += b;
state[2] += c;
state[3] += d;
}
// 把byte型数据转换为无符号long型数据
private static long byteToul(byte b) {
return b >0 ?b : ( b & 0x7F + 128);
}
// 把byte类型的数据转换成十六进制ASCII字符表示
private static String byteToHEX(byte in) {
char[] DigitStr = { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9',
'A', 'B', 'C', 'D', 'E', 'F' };
char[] out = new char[2];
out[0] = DigitStr[(in >> 4) & 0x0F]; //取高4位
out[1] = DigitStr[in & 0x0F]; //取低4位
String s = new String(out);
return s;
}
// 将long型数组按顺序拆成byte型数组,长度为len
private void Encode(byte[] output, long[] input, int len) {
int i, j;
for (i = 0, j = 0; j < len; i++, j += 4) {
output[j] = (byte) (input[i] & 0xffL);
output[j + 1] = (byte) ((input[i] >>> 8) & 0xffL);
output[j + 2] = (byte) ((input[i] >>> 16) & 0xffL);
output[j + 3] = (byte) ((input[i] >>> 24) & 0xffL);
}
}
// 将byte型数组按顺序合成long型数组,长度为len
private void Decode(long[] output, byte[] input, int len) {
int i, j;
for (i = 0, j = 0; j < len; i++, j += 4)
output[i] = byteToul(input[j])
| (byteToul(input[j + 1]) << 8)
| (byteToul(input[j + 2]) << 16)
| (byteToul(input[j + 3]) << 24);
return;
}
}
Com.filter:
package com.filter;
import java.io.IOException;
import javax.servlet.Filter;
import javax.servlet.FilterChain;
import javax.servlet.FilterConfig;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
public class LoginFilter implements Filter {
@Override
public void destroy() {
// TODO Auto-generated method stub
}
@Override
public void doFilter(ServletRequest arg0, ServletResponse arg1,
FilterChain arg2) throws IOException, ServletException {
HttpServletRequest request = (HttpServletRequest)arg0;
HttpSession session = request.getSession();
if(session.getAttribute("admins")!=null){
arg2.doFilter(arg0, arg1);
}else{
HttpServletResponse response = (HttpServletResponse)arg1;
response.sendRedirect(request.getContextPath()+"/adminlogin.jsp");
}
}
@Override
public void init(FilterConfig arg0) throws ServletException {
// TODO Auto-generated method stub
}
}
Md5test:
package com.test;
import com.utils.MD5Utils;
public class MD5Test {
public static void main(String[] args) {
// TODO Auto-generated method stub
String pass ="123456";
MD5Utils md5Utils = new MD5Utils();
String md5pass = md5Utils.getMD5ofStr(pass);
System.out.println(md5pass);
}
}
Md5utils:
package com.utils;
import java.lang.*;
import java.math.*;
/*******************************************************************************
*
*
* MD5数据加密类
*/
public class MD5Utils {
// RFC1321中定义的标准4*4矩阵的常量定义。
static final int S11 = 7,S12 = 12,S13 = 17, S14 = 22;
static final int S21 = 5,S22 = 9, S23 = 14, S24 = 20;
static final int S31 = 4,S32 = 11,S33 = 16, S34 = 23;
static final int S41 = 4 ,S42 = 10,S43 = 15, S44 = 21;
// 按RFC1321标准定义不可变byte型数组PADDING
static final byte[] PADDING = { -128, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0 };
// MD5计算过程中的3组核心数据,采用数组形式存放
private long[] state = new long[4]; // 计算状态(分别对应a b c d)
private byte[] buffer = new byte[64]; // 分配64个字节私有缓冲区
private long[] count = new long[2]; // 位个数
// 最新一次计算结果的16进制ASCII字符串表示,代表了16个字符串形式的MD5值
public String resultStr;
// 最新一次计算结果的2进制数组表示,一共16个字节,代表了128bit形式的MD5值
public byte[] digest = new byte[16];
// MD5_Encoding类提供的主要的接口函数getMD5ofStr,用来进行数据加密变换。调用其可对任意字符串进行加密运算,并以字符串形式返回加密结果。
public String getMD5ofStr(String in) {
md5Init(); // 初始化
md5Update(in.getBytes(), in.length());// 调用MD5的主计算过程
md5Final(); // 输出结果到digest数组中
for (int i = 0; i < 16; i++) {
resultStr += byteToHEX(digest[i]); // 将digest数组中的每个byte型数据转为16进制形式的字符串
}
return resultStr;
}
// 标准的构造函数,调用md5Init函数进行初始化工作
public MD5Utils() {
md5Init();
return;
}
// md5初始化函数.初始化核心变量.
private void md5Init() {
state[0] = 0x67452301L; // 定义state为RFC1321中定义的标准幻数
state[1] = 0xefcdab89L; // 定义state为RFC1321中定义的标准幻数
state[2] = 0x98badcfeL; // 定义state为RFC1321中定义的标准幻数
state[3] = 0x10325476L; // 定义state为RFC1321中定义的标准幻数
count[0] = count[1] =0L; // 初始化为0
resultStr = "";// 初始化resultStr字符串为空
for(int i=0;i<16;i++) digest[i]=0;//初始化digest数组元素为0
return;
}
//定义F G H I 为4个基数 ,即为4个基本的MD5函数,进行简单的位运算
private long F(long x, long y, long z) {
return (x & y) | ((~x) & z);
}
private long G(long x, long y, long z) {
return (x & z) | (y & (~z));
}
private long H(long x, long y, long z) {
return x ^ y ^ z;
}
private long I(long x, long y, long z) {
return y ^ (x | (~z));
}
// FF,GG,HH和II调用F,G,H,I函数进行进一步变换
private long FF(long a, long b, long c, long d, long x, long s, long ac) {
a += F(b, c, d) + x + ac;
a = ((int) a << s) | ((int) a >>> (32 - s)); //这里long型数据右移时使用无符号右移运算符>>>
a += b;
return a;
}
private long GG(long a, long b, long c, long d, long x, long s, long ac) {
a += G(b, c, d) + x + ac;
a = ((int) a << s) | ((int) a >>> (32 - s)); //这里long型数据右移时使用无符号右移运算符>>>
a += b;
return a;
}
private long HH(long a, long b, long c, long d, long x, long s, long ac) {
a += H(b, c, d) + x + ac;
a = ((int) a << s) | ((int) a >>> (32 - s));//这里long型数据右移时使用无符号右移运算符>>>
a += b;
return a;
}
private long II(long a, long b, long c, long d, long x, long s, long ac) {
a += I(b, c, d) + x + ac;
a = ((int) a << s) | ((int) a >>> (32 - s));//这里long型数据右移时使用无符号右移运算符>>>
a += b;
return a;
}
// MD5的主计算过程,input是需要变换的二进制字节串,inputlen是长度
private void md5Update(byte[] input, int inputLen) {
int i=0, index, partLen;
byte[] block = new byte[64]; // 分配64个字节缓冲区
//根据count计算index值。这里long型数据右移时使用无符号右移运算符>>>
index = (int) (count[0] >>> 3) & 0x3F;
if ((count[0] += (inputLen << 3)) < (inputLen << 3))
count[1]++;
count[1] += (inputLen >>> 29); //这里int型数据右移时使用无符号右移运算符>>>
partLen = 64 - index; //计算partLen值
if (inputLen >= partLen) {
md5Memcpy(buffer, input, index, 0, partLen);
md5Transform(buffer);
for (i = partLen; i + 63 < inputLen; i += 64) {
md5Memcpy(block, input, 0, i, 64);
md5Transform(block);
}
index = 0;
} else
i = 0;
md5Memcpy(buffer, input, index, i, inputLen - i);
}
// 整理和填写输出结果,结果放到数组digest中。
private void md5Final() {
byte[] bits = new byte[8];
int index, padLen;
Encode(bits, count, 8);
index = (int) (count[0] >>> 3) & 0x3f; //这里long型数据右移时使用无符号右移运算符>>>
padLen = (index < 56) ? (56 - index) : (120 - index);
md5Update(PADDING, padLen);
md5Update(bits, 8);
Encode(digest, state, 16);
}
// byte数组的块拷贝函数,将input数组中的起始位置为inpos,长度len的数据拷贝到output数组起始位置outpos处。
private void md5Memcpy(byte[] output, byte[] input, int outpos, int inpos,
int len) {
int i;
for (i = 0; i < len; i++)
output[outpos + i] = input[inpos + i];
}
// MD5核心变换计算程序,由md5Update函数调用,block是分块的原始字节数组
private void md5Transform(byte block[]) {
long a = state[0], b = state[1], c = state[2], d = state[3];
long[] x = new long[16];
Decode(x, block, 64);
// 进行4级级联运算
// 第1级
a = FF(a, b, c, d, x[0], S11, 0xd76aa478L); /* 1 */
d = FF(d, a, b, c, x[1], S12, 0xe8c7b756L); /* 2 */
c = FF(c, d, a, b, x[2], S13, 0x242070dbL); /* 3 */
b = FF(b, c, d, a, x[3], S14, 0xc1bdceeeL); /* 4 */
a = FF(a, b, c, d, x[4], S11, 0xf57c0fafL); /* 5 */
d = FF(d, a, b, c, x[5], S12, 0x4787c62aL); /* 6 */
c = FF(c, d, a, b, x[6], S13, 0xa8304613L); /* 7 */
b = FF(b, c, d, a, x[7], S14, 0xfd469501L); /* 8 */
a = FF(a, b, c, d, x[8], S11, 0x698098d8L); /* 9 */
d = FF(d, a, b, c, x[9], S12, 0x8b44f7afL); /* 10 */
c = FF(c, d, a, b, x[10], S13, 0xffff5bb1L); /* 11 */
b = FF(b, c, d, a, x[11], S14, 0x895cd7beL); /* 12 */
a = FF(a, b, c, d, x[12], S11, 0x6b901122L); /* 13 */
d = FF(d, a, b, c, x[13], S12, 0xfd987193L); /* 14 */
c = FF(c, d, a, b, x[14], S13, 0xa679438eL); /* 15 */
b = FF(b, c, d, a, x[15], S14, 0x49b40821L); /* 16 */
// 第2级
a = GG(a, b, c, d, x[1], S21, 0xf61e2562L); /* 17 */
d = GG(d, a, b, c, x[6], S22, 0xc040b340L); /* 18 */
c = GG(c, d, a, b, x[11], S23, 0x265e5a51L); /* 19 */
b = GG(b, c, d, a, x[0], S24, 0xe9b6c7aaL); /* 20 */
a = GG(a, b, c, d, x[5], S21, 0xd62f105dL); /* 21 */
d = GG(d, a, b, c, x[10], S22, 0x2441453L); /* 22 */
c = GG(c, d, a, b, x[15], S23, 0xd8a1e681L); /* 23 */
b = GG(b, c, d, a, x[4], S24, 0xe7d3fbc8L); /* 24 */
a = GG(a, b, c, d, x[9], S21, 0x21e1cde6L); /* 25 */
d = GG(d, a, b, c, x[14], S22, 0xc33707d6L); /* 26 */
c = GG(c, d, a, b, x[3], S23, 0xf4d50d87L); /* 27 */
b = GG(b, c, d, a, x[8], S24, 0x455a14edL); /* 28 */
a = GG(a, b, c, d, x[13], S21, 0xa9e3e905L); /* 29 */
d = GG(d, a, b, c, x[2], S22, 0xfcefa3f8L); /* 30 */
c = GG(c, d, a, b, x[7], S23, 0x676f02d9L); /* 31 */
b = GG(b, c, d, a, x[12], S24, 0x8d2a4c8aL); /* 32 */
// 第3级
a = HH(a, b, c, d, x[5], S31, 0xfffa3942L); /* 33 */
d = HH(d, a, b, c, x[8], S32, 0x8771f681L); /* 34 */
c = HH(c, d, a, b, x[11], S33, 0x6d9d6122L); /* 35 */
b = HH(b, c, d, a, x[14], S34, 0xfde5380cL); /* 36 */
a = HH(a, b, c, d, x[1], S31, 0xa4beea44L); /* 37 */
d = HH(d, a, b, c, x[4], S32, 0x4bdecfa9L); /* 38 */
c = HH(c, d, a, b, x[7], S33, 0xf6bb4b60L); /* 39 */
b = HH(b, c, d, a, x[10], S34, 0xbebfbc70L); /* 40 */
a = HH(a, b, c, d, x[13], S31, 0x289b7ec6L); /* 41 */
d = HH(d, a, b, c, x[0], S32, 0xeaa127faL); /* 42 */
c = HH(c, d, a, b, x[3], S33, 0xd4ef3085L); /* 43 */
b = HH(b, c, d, a, x[6], S34, 0x4881d05L); /* 44 */
a = HH(a, b, c, d, x[9], S31, 0xd9d4d039L); /* 45 */
d = HH(d, a, b, c, x[12], S32, 0xe6db99e5L); /* 46 */
c = HH(c, d, a, b, x[15], S33, 0x1fa27cf8L); /* 47 */
b = HH(b, c, d, a, x[2], S34, 0xc4ac5665L); /* 48 */
// 第4级
a = II(a, b, c, d, x[0], S41, 0xf4292244L); /* 49 */
d = II(d, a, b, c, x[7], S42, 0x432aff97L); /* 50 */
c = II(c, d, a, b, x[14], S43, 0xab9423a7L); /* 51 */
b = II(b, c, d, a, x[5], S44, 0xfc93a039L); /* 52 */
a = II(a, b, c, d, x[12], S41, 0x655b59c3L); /* 53 */
d = II(d, a, b, c, x[3], S42, 0x8f0ccc92L); /* 54 */
c = II(c, d, a, b, x[10], S43, 0xffeff47dL); /* 55 */
b = II(b, c, d, a, x[1], S44, 0x85845dd1L); /* 56 */
a = II(a, b, c, d, x[8], S41, 0x6fa87e4fL); /* 57 */
d = II(d, a, b, c, x[15], S42, 0xfe2ce6e0L); /* 58 */
c = II(c, d, a, b, x[6], S43, 0xa3014314L); /* 59 */
b = II(b, c, d, a, x[13], S44, 0x4e0811a1L); /* 60 */
a = II(a, b, c, d, x[4], S41, 0xf7537e82L); /* 61 */
d = II(d, a, b, c, x[11], S42, 0xbd3af235L); /* 62 */
c = II(c, d, a, b, x[2], S43, 0x2ad7d2bbL); /* 63 */
b = II(b, c, d, a, x[9], S44, 0xeb86d391L); /* 64 */
//分别累加到state[0],state[1],state[2],state[3]
state[0] += a;
state[1] += b;
state[2] += c;
state[3] += d;
}
// 把byte型数据转换为无符号long型数据
private static long byteToul(byte b) {
return b >0 ?b : ( b & 0x7F + 128);
}
// 把byte类型的数据转换成十六进制ASCII字符表示
private static String byteToHEX(byte in) {
char[] DigitStr = { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9',
'A', 'B', 'C', 'D', 'E', 'F' };
char[] out = new char[2];
out[0] = DigitStr[(in >> 4) & 0x0F]; //取高4位
out[1] = DigitStr[in & 0x0F]; //取低4位
String s = new String(out);
return s;
}
// 将long型数组按顺序拆成byte型数组,长度为len
private void Encode(byte[] output, long[] input, int len) {
int i, j;
for (i = 0, j = 0; j < len; i++, j += 4) {
output[j] = (byte) (input[i] & 0xffL);
output[j + 1] = (byte) ((input[i] >>> 8) & 0xffL);
output[j + 2] = (byte) ((input[i] >>> 16) & 0xffL);
output[j + 3] = (byte) ((input[i] >>> 24) & 0xffL);
}
}
// 将byte型数组按顺序合成long型数组,长度为len
private void Decode(long[] output, byte[] input, int len) {
int i, j;
for (i = 0, j = 0; j < len; i++, j += 4)
output[i] = byteToul(input[j])
| (byteToul(input[j + 1]) << 8)
| (byteToul(input[j + 2]) << 16)
| (byteToul(input[j + 3]) << 24);
return;
}
}
Webroot:
Adminlogin:
<%@ 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>后台管理登录</title>
<link href="images/login.css" rel="stylesheet" type="text/css" />
<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">
-->
<style type="text/css">
<!--
body {
margin-left: 0px;
margin-top: 0px;
margin-right: 0px;
margin-bottom: 0px;
background-color: #016aa9;
overflow:hidden;
}
.STYLE1 {
color: #000000;
font-size: 12px;
}
-->
</style>
</head>
<body><form name="adminloginform" action="<%=request.getContextPath() %>/doadminlogin.jsp" method="post">
<table width="100%" height="100%" border="0" cellpadding="0" cellspacing="0">
<tr>
<td><table width="962" border="0" align="center" cellpadding="0" cellspacing="0">
<tr>
<td height="235" background="images/login_03.gif"> </td>
</tr>
<tr>
<td height="53"><table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td width="394" height="53" background="images/login_05.gif"> </td>
<td width="206" background="images/login_06.gif"><table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td width="16%" height="25"><div align="right"><span class="STYLE1">用户</span></div></td>
<td width="57%" height="25"><div align="center">
<input type="text" name="adminName" style="width:105px; height:17px; background-color:#292929; border:solid 1px #7dbad7; font-size:12px; color:#6cd0ff">
</div></td>
<td width="27%" height="25"> </td>
</tr>
<tr>
<td height="25"><div align="right"><span class="STYLE1">密码</span></div></td>
<td height="25"><div align="center">
<input type="password" name="adminPass" style="width:105px; height:17px; background-color:#292929; border:solid 1px #7dbad7; font-size:12px; color:#6cd0ff">
</div></td>
<td height="25"><div align="left"><a href="javascript:document.adminloginform.submit()"><img src="images/dl.gif" width="49" height="18" border="0"></a></div></td>
</tr>
</table></td>
<td width="362" background="images/login_07.gif"> </td>
</tr>
</table></td>
</tr>
<tr>
<td height="213" background="images/login_08.gif"> </td>
</tr>
</table></td>
</tr>
</table></form>
</body>
</html>
Doadminlogin:
<%@page import="com.utils.MD5Utils"%>
<%@page import="com.domain.Admins"%>
<%@page import="com.dao.AdminsDAO"%>
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%
request.setCharacterEncoding("utf-8");
MD5Utils md5Utils = new MD5Utils();
String adminName = request.getParameter("adminName");
String adminPass = request.getParameter("adminPass");
AdminsDAO adminsDAO = new AdminsDAO();
Admins admins = adminsDAO.findByAdminName(adminName);
if (admins == null) {
response.sendRedirect(request.getContextPath()
+ "/adminlogin.jsp");
} else {
if (admins.getAdminPass().equals(
md5Utils.getMD5ofStr(adminPass))) {
session.setAttribute("admins", admins);
response.sendRedirect(request.getContextPath()
+ "/admin/main.jsp");
} else {
response.sendRedirect(request.getContextPath()
+ "/adminlogin.jsp");
}
}
%>
二.实训心得体会
电子商务正是为了适应这种以全球为市场是变化而出现和发展起来的。他可以使销售商与供应商更紧密的联系起来,以更快的满足客户的需求,也可以让商家在全球范围内选择最佳供应商,在全球市场上销售产品。电子商务基于网络技术。网络技术提供了实现电子商务的技术平台,而电子商务是网络技术的最新应用和最终目标。
为期两周的实训结束了,这次的实训给了我很大的收获也让我受益匪浅,但也给了我一个很深的触感,从最简单的开始,网站的大体框架形成,再到一步步的完善这些看似简单的流程,里面有许多细节问题是要求我们注意的,一个错误的代码的输错给整个网站带来的损失是无法估计的,所以细心和细致是必须的。经过这次的实训,我们对网站有了更深的了解,从书面的明白到真正做网站的理解。我们这次实训对我们的认识起到了很大的启发作用,使我们以后再接触网站的过程中少走弯路。也是我们对人生和社会有了更清楚的认识,任何的成功都有艰辛和汗水铺出来的,没有那么多的意外收获。