




版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
1、【精品文档】如有侵权,请联系网站删除,仅供学习与交流制作一个简单的电子商务网站.精品文档.电子商务大作业 作 业 要 求制作一个简单的电子商务网站,具有以下功能: 1) 能进行用户注册、登录。用户信息保存在数据库中。 2) 能对商品信息进行维护:增加、删除、修改。商品信息保存在数据库中。 3) 实现简单的购物车功能,能对所选择的商品进行列表显示,并对价格进行统计。 纸质报告要求: 1) 实现过程说明 2) 数据库设计说明 3) 运行效果 4) 主要源代码 一、创建用户注册、登录。用户信息保存在数据库中 1) 创建数据库表 在 MySQL 中创建一个名为homeworks 的数据库,并在该数据库
2、中创建一张名为User的表格。 字段名 数据类型 是否主键 字段名 数据类型 是否主键 LoginName VARCHAR(20) Yes Password VARCHAR(20) No FirstName VARCHAR(45) No LastName VARCHAR(45) No EmailAddress VARCHAR(45) No 2) 安装所需的第三方软件包 在 testapp/WEB-INF 新建lib 目录,并将以下需要的第三方软件包拷贝到lib 目录下:jstl.jar、standard.jar、mysql-connector-java-5.0.7-bin.jar。 3) 配置
3、 JDBC 数据源 web.xml页面类容如下: <?xml version="1.0" encoding="ISO-8859-1"?> <web-app xmlns=" xmlns:xsi="/2001/XMLSchema-instance" xsi:schemaLocation=" version="2.5"> <!- Used by the JSTL database actions -> <context-para
4、m> <param-name>javax.servlet.jsp.jstl.sql.dataSource </param-name> <param-value> jdbc:mysql:/localhost:3306/homeworks?user=root&password=root,com.mysql.jdbc.Driver </param-value> </context-param> <description> Servlet and JSP Examples. </description&
5、gt; <display-name>Servlet and JSP Examples</display-name> <servlet> <servlet-name>Test</servlet-name> <display-name>Test</display-name> <description>A test Servlet</description> <servlet-class>test.ServletTest </servlet-class> </se
6、rvlet> <servlet-mapping> <servlet-name>Test</servlet-name> <url-pattern>/Test</url-pattern> </servlet-mapping> </web-app> 4) 建立和信息录入相关的 JSP 页面 Index.jsp:网站首页 <html> <head> <title>Search in User Database</title> </head> <bo
7、dy bgcolor="white"> Welcome to my website home page <p> if you are a member please click login <p> if not then click on the registration <p> <br/> <a href="register.jsp"> <input type="button" value="registration" /> </
8、a> <a href="login.jsp"> <input type="button" value="login" /> </a> </body> </html> register.jsp:用于注册用户信息的录入。 <% page contentType="text/html" %> <% taglib prefix="c" uri=" %> <% taglib prefix="
9、fn" uri=" %> <html> <head> <title>User Entry Form</title> </head> <body> Registered User Interface <p> Please enter information about a user below: <form action="validate.jsp" method="post"> <table> <tr> <
10、;td>Login Name:</td> <td><input type="text" name="loginName" value="$fn:escapeXml(param.loginName)"> </td> <td>$fn:escapeXml(loginNameError)</td> </tr> <tr> <td>Password:</td> <td><input type="
11、text" name="password" value="$fn:escapeXml(param.password)"> </td> <td>$fn:escapeXml(passwordError)</td> </tr> <tr> <td>First Name:</td> <td><input type="text" name="firstName" value="$fn:escapeXm
12、l(param.firstName)"> </td> <td>$fn:escapeXml(firstNameError)</td> </tr> <tr> <td>Last Name:</td> <td><input type="text" name="lastName" value="$fn:escapeXml(param.lastName)"> </td> <td>$fn:escapeX
13、ml(lastNameError)</td> </tr> <tr> <td>Email Address:</td> <td><input type="text" name="emailAddress" value="$fn:escapeXml(param.emailAddress)"> </td> <td>$fn:escapeXml(emailAddressError)</td> <td>(Use for
14、mat name)</td> </tr> <tr> <td colspan=2><input type="submit" value="Submit"></td> </tr> </table> </form> </body> </html> validate.jsp:用于验证录入的用户信息 程序代码如下: <% taglib prefix="c" uri=" %> <% tag
15、lib prefix="fmt" uri=" %> <c:set var="isValid" value="true" /> <c:if test="$empty param.loginName"> <c:set var="loginNameError" scope="request" value="Login missing" /> <c:set var="isValid" v
16、alue="false" /> </c:if> <c:if test="$empty param.password"> <c:set var="passwordError" scope="request" value="Password missing" /> <c:set var="isValid" value="false" /> </c:if> <c:if test="
17、$empty param.firstName"> <c:set var="firstNameError" scope="request" value="First Name missing" /> <c:set var="isValid" value="false" /> </c:if> <c:if test="$empty param.lastName"> <c:set var="lastNam
18、eError" scope="request" value="Last Name missing" /> <c:set var="isValid" value="false" /> </c:if> <c:if test="$empty param.emailAddress"> <c:set var="emailAddressError" scope="request" value="Ema
19、il Address missing" /> <c:set var="isValid" value="false" /> </c:if> <c:choose> <c:when test="$isValid"> <jsp:forward page="store.jsp" /> </c:when> <c:otherwise> <jsp:forward page="register.jsp" /&
20、gt; </c:otherwise> </c:choose> 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
21、 update it. <sql:query var="user"> SELECT * FROM User WHERE LoginName = ? <sql:param value="$param.loginName" /> </sql:query> 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.
22、 <fmt:parseDate value="$param.registerDate" var="parsedRegisterDate" pattern="yyyy-MM-dd" /> <jsp:useBean id="now" class="java.util.Date" /> <c:choose> <c:when test="$ user.rowCount = 0"> <sql:update> INSERT IN
23、TO User (LoginName, Password, FirstName, LastName, EmailAddress) VALUES(?, ?, ?, ?, ?) <sql:param value="$param.loginName" /> <sql:param value="$param.password" /> <sql:param value="$param.firstName" /> <sql:param value="$param.lastName" /
24、> <sql:param value="$param.emailAddress" /> </sql:update> </c:when> <c:otherwise> <sql:update> UPDATE User SET Password = ?, FirstName = ?, LastName = ?, EmailAddress = ?, WHERE LoginName = ? <sql:param value="$param.password" /> <sql:par
25、am value="$param.firstName" /> <sql:param value="$param.lastName" /> <sql:param value="$param.emailAddress" /> <sql:param value="$param.loginName" /> </sql:update> </c:otherwise> </c:choose> <%- Get the new or updated
26、data from the database -%> <sql:query var="newUserInfo" scope="session"> SELECT * FROM User WHERE LoginName = ? <sql:param value="$param.loginName" /> </sql:query> <%- Redirect to the confirmation page -%> <c:redirect url="confirmation
27、.jsp" /> confirmation.jsp:用于显示已保存到数据的信息。 程序代码如下: <% page contentType="text/html" %> <% taglib prefix="c" uri=" %> <% taglib prefix="fn" uri=" %> <html> <head> <title>User Info Stored</title> </head> <b
28、ody bgcolor="white"> <form action="login.jsp" method="get"> This is the information stored in the homeworks database: <table> <c:forEach items="$newUserInfo.rows" var="row"> <c:forEach items="$row" var="column&q
29、uot;> <tr> <td align=right> <b>$fn:escapeXml(column.key):</b> </td> <td> $fn:escapeXml(column.value) </td> </tr> </c:forEach> </c:forEach> <td><input type="submit" value="GoBack"></td> </table>
30、 </body> </html> 二、用户登陆 login.jsp注册用户登陆界面 <% page contentType="text/html" %> <% taglib prefix="c" uri=" %> <% taglib prefix="fn" uri=" %> <html> <head> <title>Search in User Database</title> </head> &
31、lt;body bgcolor="white"> Registered users Landing Interface <form action="find.jsp" method="get"> <table> <tr> <td>login Name:</td> <td><input type="text" name="loginName" value="$fn:escapeXml(param.logi
32、nName)"> </td> </tr> <tr> <td>Password:</td> <td><input type="password" name=" Password" value="$fn:escapeXml(param.Password)"></td> </tr> <tr> <td><input type="submit" value="lo
33、gin"></td> </tr> </table> </form> </body> </html> Find.jsp在数据库中检索登陆界面所录入的信息 <% taglib prefix="sql" uri=" %> Execute query, with wildcard characters added to the parameter values used in the search criteria <sql:query var="userL
34、ist" scope="request"> SELECT loginName,Password FROM User WHERE loginName LIKE ? AND Password LIKE ? ORDER BY loginName <sql:param value="%$param.loginName%" /> <sql:param value="%$param.Password%" /> </sql:query> <jsp:forward page="lis
35、t.jsp" /> List.jsp显示用户登陆界面 <% page contentType="text/html" %> <% taglib prefix="c" uri=" %> <% taglib prefix="sql" uri=" %> <% taglib prefix="fn" uri=" %> <html> <head> <title>Result</title>
36、; </head> <body bgcolor="white"> <c:choose> <c:when test="$userList.rowCount = 0"> Sorry, no user were found. </c:when> <c:otherwise> Welcome to the user: <thead> <tr> </tr> </thead> <c:forEach items="$userList.r
37、ows" var="row"> <tr> <td>$fn:escapeXml(row.loginName)</td> </tr> <P> Next You could management books information <P> </c:forEach> <a href="bookindex.jsp"> <input type="button" value="Books Management"
38、/> </c:otherwise> </c:choose> </body> </html> 三、商品信息 在数据库homeworks中建立表books其内容如下: 字段名 数据类型 是否主键 Name VARCHAR(45) Yes Price VARCHAR(20) No Bookindex 书籍管理首页 <html> <head> <title>Search in User Database</title> </head> <body bgcolor="whit
39、e"> Management Books Information <p> IF you want to add books infomation and updata please check AddBook <p> IF you want to Management books infomation please check Management <p> <br/> <a href="addbooks.jsp"> <input type="button" value=&q
40、uot;AddBook" /> </a> <a href="search.jsp"> <input type="button" value="Management" /> </a> </body> </html> Addbooks.jsp 添加书籍与修改页面信息: <% page contentType="text/html" %> <% taglib prefix="c" uri=&quo
41、t; %> <% taglib prefix="fn" uri=" %> <html> <head> <title>User Entry Form</title> </head> <body> Please add or updata book informations: <form action="validate1.jsp" method="post"> <table> <tr> <td&g
42、t;Name:</td> <td><input type="text" name="Name" value="$fn:escapeXml(param.Name)"> </td> <td>$fn:escapeXml(NameError)</td> </tr> <tr> <td>Price:</td> <td><input type="text" name="Price&q
43、uot;value="$fn:escapeXml(param.Price)"> </td> <td>$fn:escapeXml(PriceError)</td> </tr> <tr> <td colspan=2><input type="submit" value="Addinfor"></td> </tr> </table> </form> </body> </html>
44、validate1.jsp用于验证录入的书籍信息 <% taglib prefix="c" uri=" %> <% taglib prefix="fmt" uri=" %> <c:set var="isValid" value="true" /> <c:if test="$empty param.Name"> <c:set var="NameError" scope="request"
45、; value="Name missing" /> <c:set var="isValid" value="false" /> </c:if> <c:if test="$empty param.Price"> <c:set var="PriceError" scope="request" value="Price missing" /> <c:set var="isValid"
46、 value="false" /> </c:if> <c:choose> <c:when test="$isValid"> <jsp:forward page="show.jsp" /> </c:when> <c:otherwise> <jsp:forward page="addbooks.jsp" /> </c:otherwise> </c:choose> show.jsp将录入的书籍信息保存道数据库
47、中 <% 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. <sql:query var="books"> SELECT * FROM books WHER
48、E Name = ? <sql:param value="$param.Name" /> </sql:query> 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. <fmt:parseDate value="$param.addbooksDate"var="parsedaddbooksDate
49、" pattern="yyyy-MM-dd" /> <jsp:useBean id="now" class="java.util.Date" /> <c:choose> <c:when test="$ books.rowCount = 0"> <sql:update> INSERT INTO books (Name, Price) VALUES(?, ?) <sql:param value="$param.Name" />
50、; <sql:param value="$param.Price" /> </sql:update> </c:when> <c:otherwise> <sql:update> UPDATE books SET Price = ? WHERE Name = ? <sql:param value="$param.Price" /> <sql:param value="$param.Name" /> </sql:update> </c:ot
51、herwise> </c:choose> <%- Get the new or updated data from the database -%> <sql:query var="newbooksInfo" scope="session"> SELECT * FROM books WHERE Name = ? <sql:param value="$param.Name" /> </sql:query> <%- Redirect to the confirmati
52、on page -%> <c:redirect url="success.jsp" /> Success.jsp显示书籍信息添加成功 <% page import="java.util.*" %> <% page contentType="text/html; charset=gb2312" %> <html> <head> <title>Search in User Database</title> </head> <body
53、 bgcolor="white"> Now time is: <%=new java.util.Date()%> <P> Add or updata the success of books information <form action="addbooks.jsp" method="get"> <td><input type="submit" value="GoBack"></td> </body> &
54、lt;/html> search.jsp查找数据库中已保存的信息 <% taglib prefix="sql" uri=" %> Execute query, with wildcard characters added to the parameter values used in the search criteria <sql:query var="booksList" scope="request"> SELECT * FROM books WHERE Name LIKE ? AND P
55、rice LIKE ? ORDER BY Name <sql:param value="%$param.Name%" /> <sql:param value="%$param.Price%" /> </sql:query> <jsp:forward page="list1.jsp" /> List1.jsp:用于显示查询到的所有数据。 <% page contentType="text/html" %> <% taglib prefix="
56、c" uri=" %> <% taglib prefix="sql" uri=" %> <% taglib prefix="fn" uri=" %> <html> <head> <title>Result</title> </head> <body bgcolor="white"> <c:choose> <c:when test="$booksList.rowCoun
57、t = 0"> Sorry, no books were found. </c:when> <c:otherwise> The following homeworks were found: <p> <table border="1"> <thead> <tr> <th>Name</th> <th>Price</th> <th>Delete</th> <th>Detail</th> </
58、tr> </thead> <c:forEach items="$booksList.rows" var="row"> <tr> <td>$fn:escapeXml(row.Name)</td> <td>$fn:escapeXml(row.Price)</td> <td> <form action="delete.jsp" method="post"> <input type="hidde
59、n" name="Name" value="$fn:escapeXml(row.Name)"> <input type="submit" value="Delete"> </form> </td> <td> <a href="catalog.jsp">detail</a> </td> </tr> </c:forEach> </table> </c:othe
60、rwise> </c:choose> </body> </html> delete.jsp删除数据库中保存的数据<% taglib prefix="sql" uri=" %> <% taglib prefix="c" uri=" %> <sql:update> DELETE FROM books WHERE Name = ? <sql:param value="$param.Name" /> </sql:update&g
61、t; <c:redirect url="search.jsp"></c:redirect> 四、购物车 catalog.jsp 文件用于显示所有可供购买商品的列表、购物车内当前的物品和价格信息 <% page language="java" contentType="text/html" %> <% taglib prefix="c" uri=" %> <% taglib prefix="fmt" uri=" %>
62、<% taglib prefix="fn" uri=" %> <html> <head> <title>Product Catalog</title> </head> <body bgcolor="white"> <h1>Product Catalog</h1> Please select a book from our catalog to read more about it and decide if you like to pur
63、chase a copy: <jsp:useBean id="catalog" scope="application" class="test.CatalogBean" Generate a list of all products with links to the product page. <ul> <c:forEach items="$ductList" var="product"> <c:url var="produc
64、tURL" value="product.jsp"> <c:param name="id" value="$product.id" /> </c:url> <li> <a href="$productURL">$fn:escapeXml()</a> </c:forEach> </ul> <jsp:useBean id="cart" scope="sessio
65、n" class="test.CartBean" <%- Show the contents of the shopping cart, if any -%> <c:if test="$!empty ductList"> Your shopping cart contains the following items: <p> <table border=0> <c:forEach items="$ductList" var="pr
66、oduct"> <tr> <td>$fn:escapeXml()</td> <td>$ <fmt:formatNumber value="$product.price" type="currency" /> </td> </tr> </c:forEach> <tr><td colspan=2><hr></td></tr> <tr> <td>
67、;<b>Total:</b></td> <td>$ <fmt:formatNumber value="$cart.total" type="currency" /> </td> </tr> </table> </c:if> </body> </html> product.jsp 用于显示当前商品的详细信息,并包将该商品加入购物车的链接 <% taglib prefix="c" uri="
68、%> <jsp:useBean id="catalog" scope="application" class="test.CatalogBean" <%- Get the specified ProductBean from the catalog -%> <c:set var="product" value="$ductsByIdparam.id" /> <jsp:useBean id="cart" scope
69、="session" class="test.CartBean" <%- Add the product to the cart -%> <c:set target="$cart" property="product" value="$product" /> <c:redirect url="catalog.jsp" />product.jsp产品信息 <% page language="java" contentType="text/html" %> <% taglib prefix="c" uri=" %> <% taglib prefix="fn" uri=" %> <html> <head> <title>Product Description</title> </head> <body bgcolor=&q
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 陕西科技大学《油画技法Ⅱ》2023-2024学年第二学期期末试卷
- 苏州科技大学天平学院《形势与政策(七)》2023-2024学年第二学期期末试卷
- 吉林科技职业技术学院《下乡写生》2023-2024学年第二学期期末试卷
- 贵州工程职业学院《地域建筑创新设计》2023-2024学年第二学期期末试卷
- 商丘职业技术学院《环境工程微生物学(全英文)》2023-2024学年第二学期期末试卷
- 郑州理工职业学院《新媒体销售》2023-2024学年第二学期期末试卷
- 运城学院《湖南地方名歌》2023-2024学年第二学期期末试卷
- 2025至2030年中国豪华欧式直按主机行业投资前景及策略咨询报告
- 厦门安防科技职业学院《制药工程综合实验》2023-2024学年第二学期期末试卷
- 衢州职业技术学院《数字信号处理含实验》2023-2024学年第二学期期末试卷
- 法在我心中-主题班会课件
- 健康、健康公平和健康决定因素定义和内容
- 痛风诊治进展p
- 贵州省遵义市各县区乡镇行政村村庄村名明细及行政区划划分代码居民村民委员会
- 应彩云幼儿园优质公开课:大班语言《天生一对》
- 机械原理课程设计-自动打印机设计说明书
- 卸料平台(落地搭设)验收记录表
- 2022更新国家开放大学电大《西方行政学说》机考4套真题题库及答案1
- 城市防洪排涝规划编制大纲解读
- 山大社会体育学案例分析
- 2022年浙江省温州市七年级下学期期末语文试卷
评论
0/150
提交评论