网上书店系统
网上书店售书系统
系统功能
1、 系统功能概述
用户进入该网站后,可以浏览该网站的商品的
,查询需要的商品的信息;用户注册登陆后,可以通过购物车选购商品,下订单;管理员可以管理货物和顾客的资料等。
2、 系统功能模块
网上书店
用找用书购用新图用
户密品本物户书片户
登码分查车管上上注 录类询理架传册
数据库设计
对于该网上书店,需要建立几个
的数据库
Member(该表用来记录注册用户的个人信息)
字段名 数据类型 说明 Logname char 登录名 Realname Char 真实姓名 Password Char 密码
Email Char 用户email
Gender Char 用户性别
Address Char 用户地址
Phone Char 用户电话
Problem Char 密码提示问
Answer Char 密码回答问题
Province Char 省份 Education Char 教育程度
Hobbies Char 爱好
Selfintro Char 自我简介
type char 用户类型
Orders(用来存储购物车上的商品)
字段名 数据类型 说明
User_name char 用户名
Goods_type char 所购物的书本名称
Goods_number char 所购的书本的数量
Book(该表用来记录书本的信息)
字段名 数据类型 说明
Id Int 书的id号
Name Varchar 书名
Type Int 书的类型;1计算机相关;2
外语相关;等等
Autho Char 作者
Press Varchar 书的出版社
Price Float 书的价格
Repertory Int 书的库存:1为有,2为无
Time Datetime 书上架的时间
Intro Varchar 书的简介
Image Varchar 书的图片
Commend int 书是否是推介品
Category(用来储存书的类型)
字段名 数据类型 说明
Id Int 惟一标识id
Type Varchar 书的类型
各模块功能介绍及实现
3、 用户注册模块
首先用户在页面reg.html中按要求填写信息,在填写完后单击”提交”按钮来提交个人信息。提交后,信息在reg.html中进行验证,如果符合条件,就会提交到reg_ok.jsp进行处理。如果用户名没有给其他用户注册,并且系统要求填写的信息都合理,那么该用户就会注册成功。
页面处理代码如下:
< %@include file=”../connect.inc” //数据库连接%>
<%!String logname,realname,passwd1,passwd2,email,gender,address,phone;
String problem,answer,province,education,selfintro,hobby;
String[]hobbies;
Boolean regAttempt=false;
%>
<%
//必须填写的项目
Logname=request.getParameter(“logname”); realname=request.getParameter(“realname”); passwd1=request.getParameter(“passwd1”); passwd2=request.getParameter(“passwd2”); email=request.getParameter(“email”); gender=request.getParameter(“gender”); address=request.getParameter(“address”); if(gender.equals(“0”))
{
Gender=”male”;
}
Else
{
Gender=”female”;
}
//非必须填写的项目
Phone=request.getParameter(“phone”);
If(phone.trim().equals(“”))
{
Phone=null;;
}
problem=request.getParameter(“problem”);
If( problem.trim().equals(“”))
{
problem =null;;
}
answer=request.getParameter(“answer”);
If(answer.trim().equals(“”))
{
answer=null;;
}
province=request.getParameter(“province”);
If(province.trim().equals(“”))
{
province =null;;
}
If(province.trim().equals(“Beijing”))
{
Province=”北京”;
}
education=request.getParameter(“education”);
If(education.trim().equals(“”))
{
education =null;;
}
If(education.trim().equals(“1”))
{
education =”高中以下程度”;
}
If(education.trim().equals(“2”))
{
education =”高中/中专”;
}
If(education.trim().equals(“3”))
{
education =”大学专科”;
}
If(education.trim().equals(“4”))
{
education =”大学本科”;
}
If(education.trim().equals(“5”))
{
education =”研究生或以上”;
}
Hobbies=request.getParameterValues(“hobbies”); Hobby=””;
If(hobbies!=null){
For(int i=0;i
4、 用户登录模块
用户在登录对话框中,在其中填写自己的登录名和密码,提交后由login.jsp进行处理,
login.jsp在数据库中查找,如果找到符合条件的用户名,并且密码正确,就会初始化一
些变量,并且将页面导向主页;如果输入的用户名或者输入的密码不正确,就会提示错
误信息。
登录处理代码如下:
<%/*
这是普通用户验证处理
通过对数据库的访问对数据的验证
*/
%>
<%@include file=”connect.inc”%%>
<%!
String logname,logpass;
Boolean loginAttempt=false;
Boolean loginOK=false; %>
<%
//验证条件
If(request.getParameterValues(“logname”)!=null &&request.getParameterValues(“logpass”)!=null) {
loginAttempt=true;
}
If(loginAttempt)
{
Logname=request.getParameter(“logname”);
Logpass=request.getParameter(“logpass”);
Logname=getStr(logname);
Logpass=getStr(logpass);
String sql=”select * from member where logname=?”+logname+”? and
password=?”+logpass”?”;
//数据库的访问
ResultSet RS=stmt.executeQuery(sql);
Int rowscount=0;
Try
{
While(RS.next())
{
Rowscount++;
}
}
Catch(Exception e)
{
}
If(rowscount!=0)
{
Session.setAttribute(“username”,logname);//验证成功后,用session记录用户名称
loginOK=true;
If(loginOK)
{
String url;
url=request.getParameter(“url”);
out..println(url);
if(url==null){
reponse.sendRedirect(“index.jsp”);
}
Else{
Response.sendRedirect(“index.jsp”);
}
}
}else{
Session.setAttribute(“username”,””);
Response.sendRedirect(“index.jsp”);
}
}
%>
5、找回密码模块
如果用户忘记了密码,就可以找回自己的密码,具体实现是:填写注册时填写的密码找
回问题和回答答案,如果正确的话系统就会显示用户的登录密码。
页面逻辑处理代码如下:
<%@page contentType=”text/html;charset=gb2312”%> <%@include file=”../connect.inc”%>
找回密码
<%!
String logname,problem,answer;
Boolean loginAttempt=false;
String errorMessage=””;
%>
<%
If(request.getParameterValues(“logname”)!=null && request. getParameterValues(“problem”)!=null && request. getParameterValues(“answer”)!=null {
loginAttempt=true;
}
If(loginAttempt)
{
Logname=request.getParameter(“logname”);
problem=request.getParameter(“problem”);
answer=request.getParameter(“answer”);
logname=getStr(logname);
problem=getStr(problem);
answer=getStr(answer);
String sql=”select * from member where logname=?”+logname+”? and
problem=?”+problem+”?and answer=?”+answer+”?”;
ResultSet RS=stmt.executeQuery(sql);
Int rowscount=0;
Try
{
While(RS.next())
{
Rowscount++;
errorMessage=RS.getString(“password”);
}
}
Catch(Exception e)
{
}
If(rowscount!=0)
{
//errorMessage=RS.getString(“password”);
}else errorMessage=”您的提示问题或者回答不正确,请重新输入~”; }
%>
5、 商品分类模块
在本商店中书本可以按照类别进行分类,在这里我们把它分为9类:计算机相关、外语相关、数学相关、物理相关、化学相关、文学、哲学、综合和其他。我们也可以按照需求再划分其他类。其原理就是检索书本数据库中的categoryp字段,找到符合条件的记录并且返回给用户。
所有商品分类处理代码如下:
<%@page contentType=”text/html;charset=gb2312”%>
书店的分类
<%@include file=”../title.jsp”%>
书的分类
<%
String SQL=”select * from category order by id”;
ResultSet RS=stmt.executeQuery(SQL);
Int i=0,k=0;
While(RS.next())
{
I=i+1;
If(k<=4)
{
String booktype,bookid;
Booktype=RS.getString(“type”);
Bookid=RS.getString(“id”);
Out.println(“+booktype+” | );
K=k+1;
}
Else
{
String booktype,bookid;
Booktype=RS.getString(“type”);
Bookid=RS.getString(“id”);
Out.println(“+booktype+” | );
Out.println(“
”);
K=0;
}
}
RS.close();
%>
【返回首页】 |