- 浏览: 6173 次
- 性别:
- 来自: 深圳
最新评论
// 实体类
// 用户信息,图书信息,订单信息
import java.util.Date;
//用户实体类
public class User {
private int id;
private String name;
private String password;
private String email;
private float account;
private String address;
private String telephone;
private Date createDate;
private int state;
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getPassword() {
return password;
}
public void setPassword(String password) {
this.password = password;
}
public String getEmail() {
return email;
}
public void setEmail(String email) {
this.email = email;
}
public float getAccount() {
return account;
}
public void setAccount(float account) {
this.account = account;
}
public String getAddress() {
return address;
}
public void setAddress(String address) {
this.address = address;
}
public String getTelephone() {
return telephone;
}
public void setTelephone(String telephone) {
this.telephone = telephone;
}
public Date getCreateDate() {
return createDate;
}
public void setCreateDate(Date createDate) {
this.createDate = createDate;
}
public int getState() {
return state;
}
public void setState(int state) {
this.state = state;
}
//图书实体类
public class Book {
private int id;
private String name;
private String auther;
private String press;
private float price;
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getAuther() {
return auther;
}
public void setAuther(String auther) {
this.auther = auther;
}
public String getPress() {
return press;
}
public void setPress(String press) {
this.press = press;
}
public float getPrice() {
return price;
}
public void setPrice(float price) {
this.price = price;
}
}
//订单信息
public class Order {
private String id;
private User user;
private float sum;
private int state;
public String getId() {
return id;
}
public void setId(String id) {
this.id = id;
}
public User getUser() {
return user;
}
public void setUser(User user) {
this.user = user;
}
public float getSum() {
return sum;
}
public void setSum(float sum) {
this.sum = sum;
}
public int getState() {
return state;
}
public void setState(int state) {
this.state = state;
}
}
//连接数据库
import java.sql.Connection;
import java.sql.DriverManager;
public class DBConn {
//连接数据库
Connection con = null;
public void getCon(){
String url = "jdbc:sqlserver://localhost:1433;database=bookshop";
String user = "sa";
String password = "svse";
String driverPath = "com.microsoft.sqlserver.jdbc.SQLServerDriver";
try {
Class.forName(driverPath);
con = DriverManager.getConnection(url, user, password);
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
//数据访问层
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Timestamp;
import java.util.Date;
import com.entity.User;
public class UserDao {
//用户访问数据层
PreparedStatement stm = null;
ResultSet rs = null;
private DBConn conn = new DBConn();
//登陆
public User login(String name,String password){
//获得连接
conn.getCon();
User user = null;
String sql = "select * from t_user where name = ? and password = ?";
try {
stm = conn.con.prepareStatement(sql);
stm.setString(1, name);
stm.setString(2, password);
rs = stm.executeQuery();
while(rs.next()){
user = new User();
user.setId(rs.getInt(1));
user.setName(name);
user.setPassword(password);
user.setEmail(rs.getString(4));
user.setAccount(rs.getFloat(5));
user.setAddress(rs.getString(6));
user.setTelephone(rs.getString(7));
user.setCreateDate(rs.getDate(8));
user.setState(rs.getInt(9));
}
} catch (SQLException e) {
e.printStackTrace();
}
finally{
close();
}
return user;
}
//注册
public User register(String name,String password,String email,float account,String address,String telephone){
conn.getCon();
User user = new User();
String sql = "insert into t_user values(?,?,?,?,?,?,?,?)";
try {
stm = conn.con.prepareStatement(sql);
stm.setString(1, name);
stm.setString(2, password);
stm.setString(3, email);
stm.setFloat(4,account);
stm.setString(5, address);
stm.setString(6, telephone);
Timestamp initTime=new Timestamp(new Date().getTime());
stm.setTimestamp(7, initTime);
stm.setInt(8, 1);
user.setName(name);
user.setPassword(password);
user.setEmail(email);
user.setAccount(account);
user.setAddress(address);
user.setTelephone(telephone);
user.setCreateDate(initTime);
user.setState(1);
stm.execute();
} catch (SQLException e) {
e.printStackTrace();
}
finally{
close();
}
return user;
}
//关闭资源
public void close(){
try{
if(rs!=null){
rs.close();
}
if(stm!=null){
stm.close();
}
if(conn.con!=null){
conn.con.close();
}
}catch(Exception e){
e.printStackTrace();
}
}
//用户消费记录
public float accountExpense(User user, float expence, String orderId) {
// TODO Auto-generated method stub
conn.getCon();
float newAccount = 0;
String sql = "update t_user set account=? where id=? ";
try {
//更改用户消费信息
stm = conn.con.prepareStatement(sql);
stm.setFloat(1, user.getAccount()-expence);
stm.setInt(2, user.getId());
stm.execute();
//更改订单信息
sql = "update t_order set state = 1 where id = ?";
stm = conn.con.prepareStatement(sql);
stm.setString(1, orderId);
stm.executeUpdate();
newAccount = user.getAccount()-expence;
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return newAccount;
}
}
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;
import com.entity.Book;
public class BookDao {
//用户访问数据层
PreparedStatement stm = null;
ResultSet rs = null;
private DBConn conn = new DBConn();
//查询图书信息
public List<Book> getAllBooks(){
conn.getCon();
List<Book> list = new ArrayList<Book>();
String sql = "select * from t_book";
try {
stm = conn.con.prepareStatement(sql);
rs = stm.executeQuery();
while(rs.next()){
Book b = new Book();
b.setId(rs.getInt(1));
b.setName(rs.getString(2));
b.setAuther(rs.getString(3));
b.setPress(rs.getString(4));
b.setPrice(rs.getFloat(5));
list.add(b);
}
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
finally{
close();
}
return list;
}
//根据图书ID查询图书信息
public Book getBookById(int id){
conn.getCon();
Book b = null;
String sql = "select * from t_book where id=?";
try {
stm = conn.con.prepareStatement(sql);
stm.setInt(1, id);
rs = stm.executeQuery();
while(rs.next()){
b = new Book();
b.setId(id);
b.setName(rs.getString(2));
b.setAuther(rs.getString(3));
b.setPress(rs.getString(4));
b.setPrice(rs.getFloat(5));
}
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
finally{
close();
}
return b;
}
//关闭资源
public void close(){
try{
if(rs!=null){
rs.close();
}
if(stm!=null){
stm.close();
}
if(conn.con!=null){
conn.con.close();
}
}catch(Exception e){
e.printStackTrace();
}
}
}
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
public class OrderDao {
//用户访问数据层
PreparedStatement stm = null;
ResultSet rs = null;
private DBConn conn = new DBConn();
public String createOrder(String id,int userId,float sum){
conn.getCon();
String result = "error";
String sql = "insert into t_order values(?,?,?,?)";
try {
stm = conn.con.prepareStatement(sql);
stm.setString(1,id);
stm.setInt(2, userId);
stm.setFloat(3, sum);
stm.setInt(4, 0);
stm.executeUpdate();
result="success";
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return result;
}
}
//业务逻辑层
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import com.dao.UserDao;
import com.entity.User;
import com.opensymphony.xwork2.Action;
import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionSupport;
public class UserAction extends ActionSupport {
private User user;
//初始化购物车
private List<Integer> cart = null;
public List<Integer> getCart() {
return cart;
}
public void setCart(List<Integer> cart) {
this.cart = cart;
}
public User getUser() {
return user;
}
public void setUser(User user) {
this.user = user;
}
private UserDao udao = new UserDao();
User returnUser = new User();
//获取action上下文
ActionContext context = ActionContext.getContext();
//获得session对象
Map session = context.getSession();
Map request=(Map) context.get("request");
//实例化购物车
public void initCart(){
cart = (List<Integer>) session.get("cart");
if(cart==null){
cart = new ArrayList<Integer>();
session.put("cart", cart);
}
else if(cart.size()>0){
cart=new ArrayList<Integer>();
session.put("cart", cart);
}
}
//登录方法
public String login() throws Exception{
returnUser = udao.login(user.getName(), user.getPassword());
if(returnUser!=null && returnUser.getPassword().equals(user.getPassword())){
session.put("user", returnUser);
initCart();
return Action.SUCCESS;
}
request.put("errorMessage","登陆失败!");
return Action.ERROR;
}
//注册方法
public String register() throws Exception{
returnUser = udao.register(user.getName(), user.getPassword(), user.getEmail(), user.getAccount(), user.getAddress(), user.getTelephone());
if(returnUser!=null && returnUser.getName().equals(user.getName())){
initCart();
return Action.SUCCESS;
}
request.put("errorMessage","注册失败!");
return Action.ERROR;
}
//安全退出
public String safeExit()throws Exception{
session.clear();
return Action.SUCCESS;
}
}
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import javax.servlet.http.HttpServletRequest;
import org.apache.struts2.ServletActionContext;
import com.dao.BookDao;
import com.entity.Book;
import com.opensymphony.xwork2.Action;
import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionSupport;
public class BookAction extends ActionSupport {
BookDao bdao = new BookDao();
//private List<Book> bookList =new ArrayList<Book>();
//图书ID
private int id;
//初始化购物车
private List<Integer> cart;
//图书实体列表
private List<Book> books = new ArrayList<Book>();
public List<Book> getBooks() {
return books;
}
public void setBooks(List<Book> books) {
this.books = books;
}
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
//获取action上下文
ActionContext context = ActionContext.getContext();
//获得session对象
Map session = context.getSession();
//获得当前的request
HttpServletRequest request = ServletActionContext.getRequest();
//获得图书列表
public String getBooksList() throws Exception{
books = bdao.getAllBooks();
//保存书架的长度
int bookCaseSize = books.size();
if(bookCaseSize==0){
return Action.ERROR;
}
request.setAttribute("bookCaseSize", bookCaseSize);
return Action.SUCCESS;
}
//将图书ID添加到购物车
public String addBookIdToCart() throws Exception{
cart = (List<Integer>) session.get("cart");
cart.add(id);
return Action.SUCCESS;
}
//显示购物车里面的信息
public String showBooksIncart() throws Exception{
cart = (List<Integer>) session.get("cart");
for(int i = 0;i<cart.size();i++){
Book book = bdao.getBookById(cart.get(i));
books.add(book);
}
session.put("books", books);
return Action.SUCCESS;
}
//删除购物车里的图书信息
public String deleteBookInCart() throws Exception{
cart=(List<Integer>) session.get("cart");
cart.remove((Object)id);
return Action.SUCCESS;
}
}
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
import org.apache.struts2.ServletActionContext;
import com.dao.OrderDao;
import com.dao.UserDao;
import com.entity.User;
import com.opensymphony.xwork2.Action;
import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionSupport;
public class OrderAction extends ActionSupport {
private String id; //订单编号
private float sum;
public String getId() {
return id;
}
public void setId(String id) {
this.id = id;
}
private OrderDao odao = new OrderDao();
private UserDao udao = new UserDao();
//获得request对象
HttpServletRequest request = ServletActionContext.getRequest();
HttpSession session = request.getSession();
User user = (User) session.getAttribute("user");
public String execute() throws Exception {
// TODO Auto-generated method stub
String result = odao.createOrder(id, user.getId(), sum);
if(result.equals("success")){
List<Integer> cart = (List<Integer>) session.getAttribute("cart");
if(cart==null){
cart = new ArrayList<Integer>();
session.setAttribute("cart", cart);
}
else if(cart.size()>0){
cart=new ArrayList<Integer>();
session.setAttribute("cart", cart);
}
return Action.SUCCESS;
}
else{
return Action.ERROR;
}
}
//更新交易信息
public String updatePayInfo()throws Exception{
float newAccount=udao.accountExpense(user, sum, id);
if(newAccount!=0){
user.setAccount(newAccount);
return Action.SUCCESS;
}
return Action.ERROR;
}
}
//structs配置
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE struts PUBLIC
"-//Apache Software Foundation//DTD Struts Configuration 2.3//EN"
"http://struts.apache.org/dtds/struts-2.3.dtd">
<struts>
<constant name="struts.enable.DynamicMethodInvocation" value="false" />
<constant name="struts.devMode" value="false" />
<package name="default" namespace="" extends="struts-default">
<!-- 登陆Action-->
<action name="login" class = "com.action.UserAction" method="login">
<result name="success" type="chain">getBooksList</result>
<result name="error">/error.jsp</result>
</action>
<!-- 注册Action-->
<action name="register" class = "com.action.UserAction" method="register">
<result name="success">/login.jsp</result>
<result name="error">/error.jsp</result>
</action>
<!-- 获得图书列表-->
<action name="getBooksList" class = "com.action.BookAction" method="getBooksList">
<result name="success">/index.jsp</result>
<result name="error">/error.jsp</result>
</action>
<!-- 将图书ID添加到购物车-->
<action name="addBookIdToCart" class = "com.action.BookAction" method="addBookIdToCart">
<result name="success" type="chain">getBooksList</result>
<result name="error">/error.jsp</result>
</action>
<!-- 显示购物车里的信息-->
<action name="showBooksIncart" class = "com.action.BookAction" method="showBooksIncart">
<result name="success">/cart.jsp</result>
<result name="error">/error.jsp</result>
</action>
<!-- 提交订单 -->
<action name="submitOrder" class="com.action.OrderAction">
<result name="success" type='chain'>updatePayInfo</result>
<result name="error">/error.jsp</result>
</action>
<!-- 更新交易信息 -->
<action name="updatePayInfo" class="com.action.OrderAction" method="updatePayInfo">
<result name="success" type='chain'>getBooksList</result>
<result name="error">/error.jsp</result>
</action>
<!-- 删除图书 -->
<action name = "deleteBookInCart" class = "com.action.BookAction" method="deleteBookInCart">
<result name="success" type='chain'>showBooksIncart</result>
<result name="error">/error.jsp</result>
</action>
<!-- 安全退出-->
<action name="safeExit" class = "com.action.UserAction" method="safeExit">
<result name="success">/login.jsp</result>
</action>
</package>
<include file="example.xml"/>
<!-- Add packages here -->
</struts>
//JSP页面
1.登陆界面
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<%@taglib prefix="s" uri="/struts-tags" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<base href="<%=basePath%>">
<title>My JSP 'login.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>
<s:form action="login">
<s:textfield key="user.name" label="账号"></s:textfield>
<s:password key="user.password" label="密码"></s:password>
<s:submit value="登陆"/>
</s:form>
<a href="register.jsp">如果你没有账号请点击此处</a>
</body>
</html>
2.注册页面
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<%@taglib prefix="s" uri="/struts-tags" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<base href="<%=basePath%>">
<title>My JSP 'register.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>
<s:form action="register">
<s:textfield key="user.name" label="账号"></s:textfield>
<s:password key="user.password" label="密码"></s:password>
<s:textfield key="user.email" label="邮箱"></s:textfield>
<s:textfield key="user.account" label="账户"></s:textfield>
<s:textfield key="user.address" label="地址"></s:textfield>
<s:textfield key="user.telephone" label="联系方式"></s:textfield>
<s:submit value="注册"/>
</s:form>
</body>
</html>
3.首页(显示所有信息)
<%@ page language="java" import="java.util.*,com.entity.*,java.text.*" pageEncoding="UTF-8"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<%@ taglib prefix="s" uri="/struts-tags"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<base href="<%=basePath%>">
<title>在线书店 地理信息学院</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>
<%
List<Integer> cart=new ArrayList<Integer>();
cart=(List<Integer>)session.getAttribute("cart");
User user=(User)session.getAttribute("user");
int cartSize=cart.size();
DecimalFormat df=new DecimalFormat("#.0");
String account=df.format(user.getAccount());
%>
<body>
<font color="#666666">你好 <a href="pinfo.jsp">${sessionScope.user.name}</a> .
账户余额:<%=account%>
书架上有 ${requestScope.bookCaseSize } 本书
<a href="showBooksIncart"><span style="color: #666666">购物车中有 <%=cartSize %>本图书</span></a>
<a href="safeQuit"><span style="color: #666666">安全退出</span></a>
${requestScope.systemMesage}
</font>
<br>
<hr/>
<center>
<table width="800" border="1" cellspacing="2">
<tr bgcolor="#666666">
<td align="center"><span style="color: #262626">图书编号</span></td>
<td align="center"><span style="color: #262626">图书名称</span></td>
<td align="center"><span style="color: #262626">作者</span></td>
<td align="center"><span style="color: #262626">出版社</span></td>
<td align="center"><span style="color: #262626">价格</span></td>
<td align="center"><span style="color: #262626">操作</span></td>
</tr>
<s:iterator value="books" var="book">
<tr>
<td align="center"><span style="color: #262626"><s:property value="#book.id"/></span></td>
<td align="center"><span style="color: #262626">《<s:property value="#book.name"/>》</span></td>
<td align="center"><span style="color: #262626"><s:property value="#book.auther"/></span></td>
<td align="center"><span style="color: #262626"><s:property value="#book.press"/></span></td>
<td align="center"><span style="color: #262626"><s:property value="#book.price"/></span></td>
<td align="center"><span style="color: #262626"><a href="addBookIdToCart?id=${book.id }">[添加到购物车]</a></span></td>
</tr>
</s:iterator>
</table>
</center>
</body>
</html>
4.错误页面信息
<%@ 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 'error.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><div align="center">
<font color="#ff0000"> 错误信息:${errorMesaage }</font><br>
</div>
</body>
</html>
5.购物车页面信息
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@page import="com.entity.Book"%>
<%@page import="com.entity.User"%>
<%@page import="java.text.SimpleDateFormat"%>
<%@page import="java.text.DecimalFormat"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<%@ taglib prefix="s" uri="/struts-tags"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<base href="<%=basePath%>">
<title>My JSP 'cart.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>
<%
float sumMoney = 0;
List<Book> books = new ArrayList<Book>();
books =(List<Book>)session.getAttribute("books");
for(int i = 0;i<books.size();i++){
sumMoney = sumMoney + books.get(i).getPrice();
}
User user =(User)session.getAttribute("user");
DecimalFormat df=new DecimalFormat("#.0");
String sumStr=df.format(sumMoney);
String accountStr=df.format(user.getAccount());
//订单号
SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMddHHmmss");
String orderStr = sdf.format(new Date());
String randomStr = Math.random()*10000+"";
orderStr = orderStr + randomStr.substring(1,3);
%>
<body>
<font color="#666666">你好 <a href="pinfo.jsp">${sessionScope.user.name}</a> .
账户余额:<%=accountStr%>
支付总额:<%=sumStr %>
<a href="getBooksList"><span style="color: #666666">返回</span></a>
${requestScope.systemMesage}
</font>
<br>
<hr/>
<center>
<table width="800" border="1" cellspacing="1">
<tr bgcolor="#666666">
<td align="center"><span style="color: #262626">图书编号</span></td>
<td align="center"><span style="color: #262626">图书名称</span></td>
<td align="center"><span style="color: #262626">作者</span></td>
<td align="center"><span style="color: #262626">出版社</span></td>
<td align="center"><span style="color: #262626">价格</span></td>
<td align="center"><span style="color: #262626">操作</span></td>
</tr>
<s:iterator value="books" var="book">
<tr>
<td align="center"><span style="color: #262626"><s:property value="#book.id"/></span></td>
<td align="center"><span style="color: #262626">《<s:property value="#book.name"/>》</span></td>
<td align="center"><span style="color: #262626"><s:property value="#book.auther"/></span></td>
<td align="center"><span style="color: #262626"><s:property value="#book.press"/></span></td>
<td align="center"><span style="color: #262626"><s:property value="#book.price"/></span></td>
<td align="center"><span style="color: #262626"><a href="deleteBookInCart?id=<s:property value="#book.id"/>"">删除</a></span></td>
</tr>
</s:iterator>
</table>
<br/>
<!--订单信息 -->
<table width="800" border="1" cellspacing="1">
<tr bgcolor="#666666">
<td align="center" width="400"><span style="color: #262626">订单号</span></td>
<td align="center" width="400"><span style="color: #262626"><%=orderStr %></span></td>
</tr>
<tr bgcolor="#666666">
<td align="center" width="400"><span style="color: #262626">收件人</span></td>
<td align="center" width="400"><span style="color: #262626">${sessionScope.user.name}</span></td>
</tr>
<tr bgcolor="#666666">
<td align="center" width="400"><span style="color: #262626">支付金额</span></td>
<td align="center" width="400"><br><br><span style="color: #262626"><%=sumMoney%></span></td>
</tr>
<tr bgcolor="#666666">
<td align="center" width="400"><span style="color: #262626">电话</span></td>
<td align="center" width="400"><span style="color: #262626">${sessionScope.user.telephone}</span></td>
</tr>
<tr bgcolor="#666666">
<td align="center" width="400"><span style="color: #262626">寄送地址</span></td>
<td align="center" width="400"><span style="color: #262626">${session.user.address}</span></td>
</tr>
</table>
<br/>
<input type="button" value="确认支付" onclick="location.href='submitOrder?id=<%=orderStr%>&sum=<%=sumStr%>'"/>
</center>
</body>
</html>
// 用户信息,图书信息,订单信息
import java.util.Date;
//用户实体类
public class User {
private int id;
private String name;
private String password;
private String email;
private float account;
private String address;
private String telephone;
private Date createDate;
private int state;
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getPassword() {
return password;
}
public void setPassword(String password) {
this.password = password;
}
public String getEmail() {
return email;
}
public void setEmail(String email) {
this.email = email;
}
public float getAccount() {
return account;
}
public void setAccount(float account) {
this.account = account;
}
public String getAddress() {
return address;
}
public void setAddress(String address) {
this.address = address;
}
public String getTelephone() {
return telephone;
}
public void setTelephone(String telephone) {
this.telephone = telephone;
}
public Date getCreateDate() {
return createDate;
}
public void setCreateDate(Date createDate) {
this.createDate = createDate;
}
public int getState() {
return state;
}
public void setState(int state) {
this.state = state;
}
//图书实体类
public class Book {
private int id;
private String name;
private String auther;
private String press;
private float price;
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getAuther() {
return auther;
}
public void setAuther(String auther) {
this.auther = auther;
}
public String getPress() {
return press;
}
public void setPress(String press) {
this.press = press;
}
public float getPrice() {
return price;
}
public void setPrice(float price) {
this.price = price;
}
}
//订单信息
public class Order {
private String id;
private User user;
private float sum;
private int state;
public String getId() {
return id;
}
public void setId(String id) {
this.id = id;
}
public User getUser() {
return user;
}
public void setUser(User user) {
this.user = user;
}
public float getSum() {
return sum;
}
public void setSum(float sum) {
this.sum = sum;
}
public int getState() {
return state;
}
public void setState(int state) {
this.state = state;
}
}
//连接数据库
import java.sql.Connection;
import java.sql.DriverManager;
public class DBConn {
//连接数据库
Connection con = null;
public void getCon(){
String url = "jdbc:sqlserver://localhost:1433;database=bookshop";
String user = "sa";
String password = "svse";
String driverPath = "com.microsoft.sqlserver.jdbc.SQLServerDriver";
try {
Class.forName(driverPath);
con = DriverManager.getConnection(url, user, password);
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
//数据访问层
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Timestamp;
import java.util.Date;
import com.entity.User;
public class UserDao {
//用户访问数据层
PreparedStatement stm = null;
ResultSet rs = null;
private DBConn conn = new DBConn();
//登陆
public User login(String name,String password){
//获得连接
conn.getCon();
User user = null;
String sql = "select * from t_user where name = ? and password = ?";
try {
stm = conn.con.prepareStatement(sql);
stm.setString(1, name);
stm.setString(2, password);
rs = stm.executeQuery();
while(rs.next()){
user = new User();
user.setId(rs.getInt(1));
user.setName(name);
user.setPassword(password);
user.setEmail(rs.getString(4));
user.setAccount(rs.getFloat(5));
user.setAddress(rs.getString(6));
user.setTelephone(rs.getString(7));
user.setCreateDate(rs.getDate(8));
user.setState(rs.getInt(9));
}
} catch (SQLException e) {
e.printStackTrace();
}
finally{
close();
}
return user;
}
//注册
public User register(String name,String password,String email,float account,String address,String telephone){
conn.getCon();
User user = new User();
String sql = "insert into t_user values(?,?,?,?,?,?,?,?)";
try {
stm = conn.con.prepareStatement(sql);
stm.setString(1, name);
stm.setString(2, password);
stm.setString(3, email);
stm.setFloat(4,account);
stm.setString(5, address);
stm.setString(6, telephone);
Timestamp initTime=new Timestamp(new Date().getTime());
stm.setTimestamp(7, initTime);
stm.setInt(8, 1);
user.setName(name);
user.setPassword(password);
user.setEmail(email);
user.setAccount(account);
user.setAddress(address);
user.setTelephone(telephone);
user.setCreateDate(initTime);
user.setState(1);
stm.execute();
} catch (SQLException e) {
e.printStackTrace();
}
finally{
close();
}
return user;
}
//关闭资源
public void close(){
try{
if(rs!=null){
rs.close();
}
if(stm!=null){
stm.close();
}
if(conn.con!=null){
conn.con.close();
}
}catch(Exception e){
e.printStackTrace();
}
}
//用户消费记录
public float accountExpense(User user, float expence, String orderId) {
// TODO Auto-generated method stub
conn.getCon();
float newAccount = 0;
String sql = "update t_user set account=? where id=? ";
try {
//更改用户消费信息
stm = conn.con.prepareStatement(sql);
stm.setFloat(1, user.getAccount()-expence);
stm.setInt(2, user.getId());
stm.execute();
//更改订单信息
sql = "update t_order set state = 1 where id = ?";
stm = conn.con.prepareStatement(sql);
stm.setString(1, orderId);
stm.executeUpdate();
newAccount = user.getAccount()-expence;
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return newAccount;
}
}
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;
import com.entity.Book;
public class BookDao {
//用户访问数据层
PreparedStatement stm = null;
ResultSet rs = null;
private DBConn conn = new DBConn();
//查询图书信息
public List<Book> getAllBooks(){
conn.getCon();
List<Book> list = new ArrayList<Book>();
String sql = "select * from t_book";
try {
stm = conn.con.prepareStatement(sql);
rs = stm.executeQuery();
while(rs.next()){
Book b = new Book();
b.setId(rs.getInt(1));
b.setName(rs.getString(2));
b.setAuther(rs.getString(3));
b.setPress(rs.getString(4));
b.setPrice(rs.getFloat(5));
list.add(b);
}
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
finally{
close();
}
return list;
}
//根据图书ID查询图书信息
public Book getBookById(int id){
conn.getCon();
Book b = null;
String sql = "select * from t_book where id=?";
try {
stm = conn.con.prepareStatement(sql);
stm.setInt(1, id);
rs = stm.executeQuery();
while(rs.next()){
b = new Book();
b.setId(id);
b.setName(rs.getString(2));
b.setAuther(rs.getString(3));
b.setPress(rs.getString(4));
b.setPrice(rs.getFloat(5));
}
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
finally{
close();
}
return b;
}
//关闭资源
public void close(){
try{
if(rs!=null){
rs.close();
}
if(stm!=null){
stm.close();
}
if(conn.con!=null){
conn.con.close();
}
}catch(Exception e){
e.printStackTrace();
}
}
}
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
public class OrderDao {
//用户访问数据层
PreparedStatement stm = null;
ResultSet rs = null;
private DBConn conn = new DBConn();
public String createOrder(String id,int userId,float sum){
conn.getCon();
String result = "error";
String sql = "insert into t_order values(?,?,?,?)";
try {
stm = conn.con.prepareStatement(sql);
stm.setString(1,id);
stm.setInt(2, userId);
stm.setFloat(3, sum);
stm.setInt(4, 0);
stm.executeUpdate();
result="success";
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return result;
}
}
//业务逻辑层
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import com.dao.UserDao;
import com.entity.User;
import com.opensymphony.xwork2.Action;
import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionSupport;
public class UserAction extends ActionSupport {
private User user;
//初始化购物车
private List<Integer> cart = null;
public List<Integer> getCart() {
return cart;
}
public void setCart(List<Integer> cart) {
this.cart = cart;
}
public User getUser() {
return user;
}
public void setUser(User user) {
this.user = user;
}
private UserDao udao = new UserDao();
User returnUser = new User();
//获取action上下文
ActionContext context = ActionContext.getContext();
//获得session对象
Map session = context.getSession();
Map request=(Map) context.get("request");
//实例化购物车
public void initCart(){
cart = (List<Integer>) session.get("cart");
if(cart==null){
cart = new ArrayList<Integer>();
session.put("cart", cart);
}
else if(cart.size()>0){
cart=new ArrayList<Integer>();
session.put("cart", cart);
}
}
//登录方法
public String login() throws Exception{
returnUser = udao.login(user.getName(), user.getPassword());
if(returnUser!=null && returnUser.getPassword().equals(user.getPassword())){
session.put("user", returnUser);
initCart();
return Action.SUCCESS;
}
request.put("errorMessage","登陆失败!");
return Action.ERROR;
}
//注册方法
public String register() throws Exception{
returnUser = udao.register(user.getName(), user.getPassword(), user.getEmail(), user.getAccount(), user.getAddress(), user.getTelephone());
if(returnUser!=null && returnUser.getName().equals(user.getName())){
initCart();
return Action.SUCCESS;
}
request.put("errorMessage","注册失败!");
return Action.ERROR;
}
//安全退出
public String safeExit()throws Exception{
session.clear();
return Action.SUCCESS;
}
}
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import javax.servlet.http.HttpServletRequest;
import org.apache.struts2.ServletActionContext;
import com.dao.BookDao;
import com.entity.Book;
import com.opensymphony.xwork2.Action;
import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionSupport;
public class BookAction extends ActionSupport {
BookDao bdao = new BookDao();
//private List<Book> bookList =new ArrayList<Book>();
//图书ID
private int id;
//初始化购物车
private List<Integer> cart;
//图书实体列表
private List<Book> books = new ArrayList<Book>();
public List<Book> getBooks() {
return books;
}
public void setBooks(List<Book> books) {
this.books = books;
}
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
//获取action上下文
ActionContext context = ActionContext.getContext();
//获得session对象
Map session = context.getSession();
//获得当前的request
HttpServletRequest request = ServletActionContext.getRequest();
//获得图书列表
public String getBooksList() throws Exception{
books = bdao.getAllBooks();
//保存书架的长度
int bookCaseSize = books.size();
if(bookCaseSize==0){
return Action.ERROR;
}
request.setAttribute("bookCaseSize", bookCaseSize);
return Action.SUCCESS;
}
//将图书ID添加到购物车
public String addBookIdToCart() throws Exception{
cart = (List<Integer>) session.get("cart");
cart.add(id);
return Action.SUCCESS;
}
//显示购物车里面的信息
public String showBooksIncart() throws Exception{
cart = (List<Integer>) session.get("cart");
for(int i = 0;i<cart.size();i++){
Book book = bdao.getBookById(cart.get(i));
books.add(book);
}
session.put("books", books);
return Action.SUCCESS;
}
//删除购物车里的图书信息
public String deleteBookInCart() throws Exception{
cart=(List<Integer>) session.get("cart");
cart.remove((Object)id);
return Action.SUCCESS;
}
}
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
import org.apache.struts2.ServletActionContext;
import com.dao.OrderDao;
import com.dao.UserDao;
import com.entity.User;
import com.opensymphony.xwork2.Action;
import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionSupport;
public class OrderAction extends ActionSupport {
private String id; //订单编号
private float sum;
public String getId() {
return id;
}
public void setId(String id) {
this.id = id;
}
private OrderDao odao = new OrderDao();
private UserDao udao = new UserDao();
//获得request对象
HttpServletRequest request = ServletActionContext.getRequest();
HttpSession session = request.getSession();
User user = (User) session.getAttribute("user");
public String execute() throws Exception {
// TODO Auto-generated method stub
String result = odao.createOrder(id, user.getId(), sum);
if(result.equals("success")){
List<Integer> cart = (List<Integer>) session.getAttribute("cart");
if(cart==null){
cart = new ArrayList<Integer>();
session.setAttribute("cart", cart);
}
else if(cart.size()>0){
cart=new ArrayList<Integer>();
session.setAttribute("cart", cart);
}
return Action.SUCCESS;
}
else{
return Action.ERROR;
}
}
//更新交易信息
public String updatePayInfo()throws Exception{
float newAccount=udao.accountExpense(user, sum, id);
if(newAccount!=0){
user.setAccount(newAccount);
return Action.SUCCESS;
}
return Action.ERROR;
}
}
//structs配置
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE struts PUBLIC
"-//Apache Software Foundation//DTD Struts Configuration 2.3//EN"
"http://struts.apache.org/dtds/struts-2.3.dtd">
<struts>
<constant name="struts.enable.DynamicMethodInvocation" value="false" />
<constant name="struts.devMode" value="false" />
<package name="default" namespace="" extends="struts-default">
<!-- 登陆Action-->
<action name="login" class = "com.action.UserAction" method="login">
<result name="success" type="chain">getBooksList</result>
<result name="error">/error.jsp</result>
</action>
<!-- 注册Action-->
<action name="register" class = "com.action.UserAction" method="register">
<result name="success">/login.jsp</result>
<result name="error">/error.jsp</result>
</action>
<!-- 获得图书列表-->
<action name="getBooksList" class = "com.action.BookAction" method="getBooksList">
<result name="success">/index.jsp</result>
<result name="error">/error.jsp</result>
</action>
<!-- 将图书ID添加到购物车-->
<action name="addBookIdToCart" class = "com.action.BookAction" method="addBookIdToCart">
<result name="success" type="chain">getBooksList</result>
<result name="error">/error.jsp</result>
</action>
<!-- 显示购物车里的信息-->
<action name="showBooksIncart" class = "com.action.BookAction" method="showBooksIncart">
<result name="success">/cart.jsp</result>
<result name="error">/error.jsp</result>
</action>
<!-- 提交订单 -->
<action name="submitOrder" class="com.action.OrderAction">
<result name="success" type='chain'>updatePayInfo</result>
<result name="error">/error.jsp</result>
</action>
<!-- 更新交易信息 -->
<action name="updatePayInfo" class="com.action.OrderAction" method="updatePayInfo">
<result name="success" type='chain'>getBooksList</result>
<result name="error">/error.jsp</result>
</action>
<!-- 删除图书 -->
<action name = "deleteBookInCart" class = "com.action.BookAction" method="deleteBookInCart">
<result name="success" type='chain'>showBooksIncart</result>
<result name="error">/error.jsp</result>
</action>
<!-- 安全退出-->
<action name="safeExit" class = "com.action.UserAction" method="safeExit">
<result name="success">/login.jsp</result>
</action>
</package>
<include file="example.xml"/>
<!-- Add packages here -->
</struts>
//JSP页面
1.登陆界面
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<%@taglib prefix="s" uri="/struts-tags" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<base href="<%=basePath%>">
<title>My JSP 'login.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>
<s:form action="login">
<s:textfield key="user.name" label="账号"></s:textfield>
<s:password key="user.password" label="密码"></s:password>
<s:submit value="登陆"/>
</s:form>
<a href="register.jsp">如果你没有账号请点击此处</a>
</body>
</html>
2.注册页面
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<%@taglib prefix="s" uri="/struts-tags" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<base href="<%=basePath%>">
<title>My JSP 'register.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>
<s:form action="register">
<s:textfield key="user.name" label="账号"></s:textfield>
<s:password key="user.password" label="密码"></s:password>
<s:textfield key="user.email" label="邮箱"></s:textfield>
<s:textfield key="user.account" label="账户"></s:textfield>
<s:textfield key="user.address" label="地址"></s:textfield>
<s:textfield key="user.telephone" label="联系方式"></s:textfield>
<s:submit value="注册"/>
</s:form>
</body>
</html>
3.首页(显示所有信息)
<%@ page language="java" import="java.util.*,com.entity.*,java.text.*" pageEncoding="UTF-8"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<%@ taglib prefix="s" uri="/struts-tags"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<base href="<%=basePath%>">
<title>在线书店 地理信息学院</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>
<%
List<Integer> cart=new ArrayList<Integer>();
cart=(List<Integer>)session.getAttribute("cart");
User user=(User)session.getAttribute("user");
int cartSize=cart.size();
DecimalFormat df=new DecimalFormat("#.0");
String account=df.format(user.getAccount());
%>
<body>
<font color="#666666">你好 <a href="pinfo.jsp">${sessionScope.user.name}</a> .
账户余额:<%=account%>
书架上有 ${requestScope.bookCaseSize } 本书
<a href="showBooksIncart"><span style="color: #666666">购物车中有 <%=cartSize %>本图书</span></a>
<a href="safeQuit"><span style="color: #666666">安全退出</span></a>
${requestScope.systemMesage}
</font>
<br>
<hr/>
<center>
<table width="800" border="1" cellspacing="2">
<tr bgcolor="#666666">
<td align="center"><span style="color: #262626">图书编号</span></td>
<td align="center"><span style="color: #262626">图书名称</span></td>
<td align="center"><span style="color: #262626">作者</span></td>
<td align="center"><span style="color: #262626">出版社</span></td>
<td align="center"><span style="color: #262626">价格</span></td>
<td align="center"><span style="color: #262626">操作</span></td>
</tr>
<s:iterator value="books" var="book">
<tr>
<td align="center"><span style="color: #262626"><s:property value="#book.id"/></span></td>
<td align="center"><span style="color: #262626">《<s:property value="#book.name"/>》</span></td>
<td align="center"><span style="color: #262626"><s:property value="#book.auther"/></span></td>
<td align="center"><span style="color: #262626"><s:property value="#book.press"/></span></td>
<td align="center"><span style="color: #262626"><s:property value="#book.price"/></span></td>
<td align="center"><span style="color: #262626"><a href="addBookIdToCart?id=${book.id }">[添加到购物车]</a></span></td>
</tr>
</s:iterator>
</table>
</center>
</body>
</html>
4.错误页面信息
<%@ 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 'error.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><div align="center">
<font color="#ff0000"> 错误信息:${errorMesaage }</font><br>
</div>
</body>
</html>
5.购物车页面信息
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@page import="com.entity.Book"%>
<%@page import="com.entity.User"%>
<%@page import="java.text.SimpleDateFormat"%>
<%@page import="java.text.DecimalFormat"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<%@ taglib prefix="s" uri="/struts-tags"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<base href="<%=basePath%>">
<title>My JSP 'cart.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>
<%
float sumMoney = 0;
List<Book> books = new ArrayList<Book>();
books =(List<Book>)session.getAttribute("books");
for(int i = 0;i<books.size();i++){
sumMoney = sumMoney + books.get(i).getPrice();
}
User user =(User)session.getAttribute("user");
DecimalFormat df=new DecimalFormat("#.0");
String sumStr=df.format(sumMoney);
String accountStr=df.format(user.getAccount());
//订单号
SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMddHHmmss");
String orderStr = sdf.format(new Date());
String randomStr = Math.random()*10000+"";
orderStr = orderStr + randomStr.substring(1,3);
%>
<body>
<font color="#666666">你好 <a href="pinfo.jsp">${sessionScope.user.name}</a> .
账户余额:<%=accountStr%>
支付总额:<%=sumStr %>
<a href="getBooksList"><span style="color: #666666">返回</span></a>
${requestScope.systemMesage}
</font>
<br>
<hr/>
<center>
<table width="800" border="1" cellspacing="1">
<tr bgcolor="#666666">
<td align="center"><span style="color: #262626">图书编号</span></td>
<td align="center"><span style="color: #262626">图书名称</span></td>
<td align="center"><span style="color: #262626">作者</span></td>
<td align="center"><span style="color: #262626">出版社</span></td>
<td align="center"><span style="color: #262626">价格</span></td>
<td align="center"><span style="color: #262626">操作</span></td>
</tr>
<s:iterator value="books" var="book">
<tr>
<td align="center"><span style="color: #262626"><s:property value="#book.id"/></span></td>
<td align="center"><span style="color: #262626">《<s:property value="#book.name"/>》</span></td>
<td align="center"><span style="color: #262626"><s:property value="#book.auther"/></span></td>
<td align="center"><span style="color: #262626"><s:property value="#book.press"/></span></td>
<td align="center"><span style="color: #262626"><s:property value="#book.price"/></span></td>
<td align="center"><span style="color: #262626"><a href="deleteBookInCart?id=<s:property value="#book.id"/>"">删除</a></span></td>
</tr>
</s:iterator>
</table>
<br/>
<!--订单信息 -->
<table width="800" border="1" cellspacing="1">
<tr bgcolor="#666666">
<td align="center" width="400"><span style="color: #262626">订单号</span></td>
<td align="center" width="400"><span style="color: #262626"><%=orderStr %></span></td>
</tr>
<tr bgcolor="#666666">
<td align="center" width="400"><span style="color: #262626">收件人</span></td>
<td align="center" width="400"><span style="color: #262626">${sessionScope.user.name}</span></td>
</tr>
<tr bgcolor="#666666">
<td align="center" width="400"><span style="color: #262626">支付金额</span></td>
<td align="center" width="400"><br><br><span style="color: #262626"><%=sumMoney%></span></td>
</tr>
<tr bgcolor="#666666">
<td align="center" width="400"><span style="color: #262626">电话</span></td>
<td align="center" width="400"><span style="color: #262626">${sessionScope.user.telephone}</span></td>
</tr>
<tr bgcolor="#666666">
<td align="center" width="400"><span style="color: #262626">寄送地址</span></td>
<td align="center" width="400"><span style="color: #262626">${session.user.address}</span></td>
</tr>
</table>
<br/>
<input type="button" value="确认支付" onclick="location.href='submitOrder?id=<%=orderStr%>&sum=<%=sumStr%>'"/>
</center>
</body>
</html>
相关推荐
Java Web小项目是一个全面展示Java Web开发核心技术的实践案例,旨在帮助开发者对这一领域有深入的理解和整体把握。在这个项目中,"bookshopping"很可能是书店购物系统的名称,通过它我们可以探讨一系列关键知识点。...
Java Web小项目在线书店源码是一个综合性的学习资源,它涵盖了Java Web开发的多个核心知识点。这个项目旨在帮助开发者对Java Web技术有更全面、深入的理解。通过分析和研究这个项目,我们可以学习到以下关键技术和...
本项目为基于SSM框架的Java Web小项目实践设计源码,包含1070个文件,涵盖494个JavaScript脚本、162个CSS样式表、138个HTML页面、154个PNG图片、24个JPG图片、16个Markdown文档、13个文本文件、9个JSP页面、7个Java...
最常见的JAVA Web 小项目,一般入门的基础小题目以及要求
"足球联赛Java web 小项目"是一个基于Java EE技术栈的Web应用程序,主要用于模拟和管理足球联赛的各类数据和功能。这样的项目通常包括球队管理、球员信息维护、比赛日程安排、比赛结果记录等功能,是Java Web开发...
JAVA WEB 校园订餐系统项目源码+数据库 JAVA WEB 校园订餐系统项目源码+数据库 JAVA WEB 校园订餐系统项目源码+数据库 JAVA WEB 校园订餐系统项目源码+数据库 JAVA WEB 校园订餐系统项目源码+数据库 JAVA WEB 校园...
JavaWeb是Java技术在Web应用开发中的应用,涵盖了Servlet、JSP、JDBC、MVC框架(如Spring MVC)、JSF、WebSocket等技术。这个压缩包"34个经典javaweb项目实例.zip"提供了丰富的实践资源,对于学习者来说是宝贵的资料...
在IT行业中,尤其是在Java Web项目的开发与维护过程中,自动化打补丁包是一个高效且重要的环节。这个过程可以显著提升开发团队的工作效率,减少手动操作带来的错误,并确保项目的稳定性和安全性。下面将详细解释标题...
5. **Eclipse/MyEclipse**:这两款都是流行的Java集成开发环境,支持JAVA WEB项目的开发、调试和部署。Eclipse是开源的,MyEclipse是其商业版本,提供了更多的企业级特性。 6. **MVC架构**:Model-View-Controller...
【标题】"java开源web项目1"所涉及的知识点主要集中在Java编程语言和Web应用程序开发领域,这通常意味着这是一个基于Java技术栈的开源Web项目。Java作为一种广泛使用的面向对象编程语言,具有平台无关性、安全性和...
2. **Eclipse IDE**:Eclipse是一种广泛使用的Java集成开发环境,支持创建、调试和部署Java Web项目。开发者可以使用Eclipse来导入这些项目,并进行代码编辑、重构和调试。 3. **数据库连接**:项目中通常会包含一...
【Java Web应用开发项目教程】是由资深讲师聂明编写的,旨在帮助学习者掌握Java Web应用程序的开发技术。本教程以实战项目为导向,通过详细的教学PPT,将理论与实践相结合,让学习者能深入理解并应用Java Web开发的...
在MyEclipse中,你可以方便地创建、运行和调试Java Web项目,包括编写源代码、管理数据库连接以及部署到Tomcat服务器。 5. **路径配置**:项目可能涉及到配置文件,如`web.xml`(Web应用的部署描述符)或应用的配置...
Java Web项目开发案例精粹是针对使用Java语言进行Web应用程序开发的一个重要资源集合,它包含了丰富的源代码示例,旨在帮助开发者深入理解并实践Java Web技术。这些源代码实例覆盖了从基础到高级的各种应用场景,有...
Java Web 项目开发需要掌握的技术栈 Java Web 项目开发需要掌握哪些技术?这是每个 Java Web 开发人员都需要了解的问题。 Java Web 项目开发 涉及到多个技术领域,包括 Java 语言、Web 服务器、数据库连接、网页...
Java Web 项目打包 WAR 格式详解 Java Web 项目打包是指将 Java 项目编译后的 class 文件、资源文件、配置文件等打包成一个 WAR 文件,以便于部署到 Web 服务器中。WAR 文件是一个压缩文件,包含了 Java 项目的所有...
在深入体验Java Web项目开发的过程中,我们将会探讨一系列关键技术和概念,这些都是构建高效、可扩展的Web应用程序的基础。首先,Java Web项目开发是基于Java技术栈的,它结合了服务器端编程、数据库交互以及前端...
这是一个基于Java技术的Web项目,主要关注的是企业事务管理系统的实现。这个系统源码的提供,对于学习和理解Java在企业级应用中的实践具有很高的价值。以下将详细讲解与Java Web项目相关的知识点。 1. **Java编程...
web系统Licence验证 保证java web ,可以现在IP,mac,自定义参数,License生成器 (JAVA源码+界面) 其中包括license授权机制的原理和制作license的具体步骤 增加了mac 地址验证
myEclipse 创建的 java Web项目的目录结构说明