制作一個(gè)簡(jiǎn)單的電子商務(wù)網(wǎng)站_第1頁(yè)
制作一個(gè)簡(jiǎn)單的電子商務(wù)網(wǎng)站_第2頁(yè)
制作一個(gè)簡(jiǎn)單的電子商務(wù)網(wǎng)站_第3頁(yè)
制作一個(gè)簡(jiǎn)單的電子商務(wù)網(wǎng)站_第4頁(yè)
制作一個(gè)簡(jiǎn)單的電子商務(wù)網(wǎng)站_第5頁(yè)
已閱讀5頁(yè),還剩15頁(yè)未讀 繼續(xù)免費(fèi)閱讀

下載本文檔

版權(quán)說(shuō)明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請(qǐng)進(jìn)行舉報(bào)或認(rèn)領(lǐng)

文檔簡(jiǎn)介

1、【精品文檔】如有侵權(quán),請(qǐng)聯(lián)系網(wǎng)站刪除,僅供學(xué)習(xí)與交流制作一個(gè)簡(jiǎn)單的電子商務(wù)網(wǎng)站.精品文檔.電子商務(wù)大作業(yè) 作 業(yè) 要 求制作一個(gè)簡(jiǎn)單的電子商務(wù)網(wǎng)站,具有以下功能: 1) 能進(jìn)行用戶注冊(cè)、登錄。用戶信息保存在數(shù)據(jù)庫(kù)中。 2) 能對(duì)商品信息進(jìn)行維護(hù):增加、刪除、修改。商品信息保存在數(shù)據(jù)庫(kù)中。 3) 實(shí)現(xiàn)簡(jiǎn)單的購(gòu)物車功能,能對(duì)所選擇的商品進(jìn)行列表顯示,并對(duì)價(jià)格進(jìn)行統(tǒng)計(jì)。 紙質(zhì)報(bào)告要求: 1) 實(shí)現(xiàn)過(guò)程說(shuō)明 2) 數(shù)據(jù)庫(kù)設(shè)計(jì)說(shuō)明 3) 運(yùn)行效果 4) 主要源代碼 一、創(chuàng)建用戶注冊(cè)、登錄。用戶信息保存在數(shù)據(jù)庫(kù)中 1) 創(chuàng)建數(shù)據(jù)庫(kù)表 在 MySQL 中創(chuàng)建一個(gè)名為homeworks 的數(shù)據(jù)庫(kù),并在該數(shù)據(jù)庫(kù)

2、中創(chuàng)建一張名為User的表格。 字段名 數(shù)據(jù)類型 是否主鍵 字段名 數(shù)據(jù)類型 是否主鍵 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 數(shù)據(jù)源 web.xml頁(yè)面類容如下: <?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&amp;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) 建立和信息錄入相關(guān)的 JSP 頁(yè)面 Index.jsp:網(wǎng)站首頁(yè) <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:用于注冊(cè)用戶信息的錄入。 <% 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:用于驗(yàn)證錄入的用戶信息 程序代碼如下: <% 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:用于將錄入的信息保存到數(shù)據(jù)庫(kù)中。 程序代碼如下: <% 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:用于顯示已保存到數(shù)據(jù)的信息。 程序代碼如下: <% 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注冊(cè)用戶登陸界面 <% 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在數(shù)據(jù)庫(kù)中檢索登陸界面所錄入的信息 <% 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> 三、商品信息 在數(shù)據(jù)庫(kù)homeworks中建立表books其內(nèi)容如下: 字段名 數(shù)據(jù)類型 是否主鍵 Name VARCHAR(45) Yes Price VARCHAR(20) No Bookindex 書(shū)籍管理首頁(yè) <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 添加書(shū)籍與修改頁(yè)面信息: <% 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用于驗(yàn)證錄入的書(shū)籍信息 <% 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將錄入的書(shū)籍信息保存道數(shù)據(jù)庫(kù)

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顯示書(shū)籍信息添加成功 <% 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查找數(shù)據(jù)庫(kù)中已保存的信息 <% 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:用于顯示查詢到的所有數(shù)據(jù)。 <% 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刪除數(shù)據(jù)庫(kù)中保存的數(shù)據(jù)<% 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> 四、購(gòu)物車 catalog.jsp 文件用于顯示所有可供購(gòu)買商品的列表、購(gòu)物車內(nèi)當(dāng)前的物品和價(jià)格信息 <% 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 用于顯示當(dāng)前商品的詳細(xì)信息,并包將該商品加入購(gòu)物車的鏈接 <% 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產(chǎn)品信息 <% 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. 本站所有資源如無(wú)特殊說(shuō)明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請(qǐng)下載最新的WinRAR軟件解壓。
  • 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請(qǐng)聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
  • 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁(yè)內(nèi)容里面會(huì)有圖紙預(yù)覽,若沒(méi)有圖紙預(yù)覽就沒(méi)有圖紙。
  • 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
  • 5. 人人文庫(kù)網(wǎng)僅提供信息存儲(chǔ)空間,僅對(duì)用戶上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對(duì)用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對(duì)任何下載內(nèi)容負(fù)責(zé)。
  • 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請(qǐng)與我們聯(lián)系,我們立即糾正。
  • 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時(shí)也不承擔(dān)用戶因使用這些下載資源對(duì)自己和他人造成任何形式的傷害或損失。

最新文檔

評(píng)論

0/150

提交評(píng)論