电子商务大作业
作业要求
制作一个简单的电子商务网站,具有以下功能:
1) 能进行用户注册、登录。用户信息保存在数据库中。
2) 能对商品信息进行维护:增加、删除、修改。商品信息保存在数据库中。
3) 实现简单的购物车功能,能对所选择的商品进行列表显示,并对价格进行统计。
纸质报告要求:
1) 实现过程说明
2) 数据库设计说明
3) 运行效果
4) 主要源代码
一、创建用户注册、登录。用户信息保存在数据库中
1) 创建数据库表
在MySQL 中创建一个名为homeworks 的数据库,并在该数据库中创建一张名为User的表格。字段名数据类型
2) 安装所需的第三方软件包
在testapp/WEB-INF 新建lib 目录,并将以下需要的第三方软件包拷贝到lib 目录下:jstl.jar、standard.jar、mysql-connector-java-5.0.7-bin.jar。
3) 配置 JDBC 数据源
web.xml页面类容如下:
xmlns:xsi="" xsi:schemaLocation=" " version="2.5"> jdbc:mysql://localhost:3306/homeworks?user=root&password=root,com.mysql.jdbc.D river Servlet and JSP Examples.
4) 建立和信息录入相关的 JSP 页面
Index.jsp:网站首页
Welcome to my website home page
if you are a member please click login
if not then click on the registration
register.jsp:用于注册用户信息的录入。
<%@ page contentType="text/html" %>
<%@ taglib prefix="c" uri="" %>
<%@ taglib prefix="fn" uri="" %>
Registered User Interface
Please enter information about a user below:
validate.jsp:用于验证录入的用户信息
程序代码如下:
<%@ taglib prefix="c" uri="" %>
<%@ taglib prefix="fmt" uri="" %>
value="Login missing" /> value="Password missing" /> value="First Name missing" /> value="Last Name missing" /> value="Email Address missing" /> store.jsp:用于将录入的信息保存到数据库中。 程序代码如下: <%@ taglib prefix="c" uri="" %> <%@ taglib prefix="sql" uri="" %> <%@ taglib prefix="fmt" uri="" %> <%-- See if the user is already defined. If not, insert the info, else update it. --%> SELECT * FROM User WHERE LoginName = ? <%-- Deal with the date values: parse the register date and create a Date object from it, and create a new variable to hold the current date. --%> INSERT INTO User (LoginName, Password, FirstName, LastName, EmailAddress) VALUES(?, ?, ?, ?, ?) UPDATE User SET Password = ?, FirstName = ?, LastName = ?, EmailAddress = ?, WHERE LoginName = ? <%-- Get the new or updated data from the database --%> SELECT * FROM User WHERE LoginName = ? <%-- Redirect to the confirmation page --%> confirmation.jsp:用于显示已保存到数据的信息。 程序代码如下: <%@ page contentType="text/html" %> <%@ taglib prefix="c" uri="" %> <%@ taglib prefix="fn" uri="" %> This is the information stored in the homeworks database: ${fn:escapeXml(column.key)}: ${fn:escapeXml(column.value)}
二、用户登陆
login.jsp注册用户登陆界面
<%@ page contentType="text/html" %>
<%@ taglib prefix="c" uri="" %>
<%@ taglib prefix="fn" uri="" %>
Registered users Landing Interface
Find.jsp在数据库中检索登陆界面所录入的信息<%@ taglib prefix="sql" uri="" %>
<%--
Execute query, with wildcard characters added to the parameter values used in the search criteria
--%>
AND Password LIKE ?
ORDER BY loginName
List.jsp显示用户登陆界面
<%@ page contentType="text/html" %>
<%@ taglib prefix="c" uri="" %>
<%@ taglib prefix="sql" uri="" %>
<%@ taglib prefix="fn" uri="" %>
Welcome to the user:
${fn:escapeXml(row.loginName)}
Next You could management books information
三、商品信息
在数据库homeworks
Bookindex 书籍管理首页
Management Books Information
IF you want to add books infomation and updata please check AddBook
IF you want to Management books infomation please check Management
Addbooks.jsp 添加书籍与修改页面信息:
<%@ page contentType="text/html" %>
<%@ taglib prefix="c" uri="" %>
<%@ taglib prefix="fn" uri="" %>
Please add or updata book informations:
validate1.jsp用于验证录入的书籍信息
<%@ taglib prefix="c" uri="" %>
<%@ taglib prefix="fmt" uri="" %>
value="Name missing" /> value="Price missing" /> show.jsp将录入的书籍信息保存道数据库中 <%@ taglib prefix="c" uri="" %> <%@ taglib prefix="sql" uri="" %> <%@ taglib prefix="fmt" uri="" %> <%-- See if the user is already defined. If not, insert the info, else update it. --%> SELECT * FROM books WHERE Name = ? <%-- Deal with the date values: parse the register date and create a Date object from it, and create a new variable to hold the current date. --%> value="${param.addbooksDate}"var="parsedaddbooksDate" pattern="yyyy-MM-dd" /> INSERT INTO books (Name, Price) VALUES(?, ?) UPDATE books SET Price = ? WHERE Name = ? <%-- Get the new or updated data from the database --%> SELECT * FROM books WHERE Name = ? <%-- Redirect to the confirmation page --%> Success.jsp显示书籍信息添加成功 <%@ page import="java.util.*" %> <%@ page contentType="text/html; charset=gb2312" %>
Now time is: <%=new java.util.Date()%>
Add or updata the success of books information