基于javaweb和mysql的ssh网上书店图书商城(java+ssh+mysql+jsp)

基于javaweb和mysql的ssh网上书店图书商城(java+ssh+mysql+jsp)

基于javaweb和mysql的ssh网上书店图书商城(java+ssh+mysql+jsp)

私信源码获取及调试交流

私信源码获取及调试交流

运行环境

Java≥8、MySQL≥5.7、Tomcat≥8

开发工具

eclipse/idea/myeclipse/sts等均可配置运行

适用

课程设计,大作业,毕业设计,项目练习,学习演示等

功能说明

基于javaweb的SSH网上书店图书商城(java+ssh+mysql+jsp)

后台:http://localhost:8080/manage/login.jsp

管理员:

admin 123456

前台:http://localhost:8080

用户:

user1 123456

user2 123456

	
	

	private File uploadfile;

	public File getUploadfile() {
		return uploadfile;
	}

	public void setUploadfile(File uploadfile) {
		this.uploadfile = uploadfile;
	}
//添加商品操作
	public void productadd2() throws IOException {
		HttpServletRequest request = ServletActionContext.getRequest();
		String name = request.getParameter("name");
		String cid = request.getParameter("cid");
		String price1 = request.getParameter("price1");
		String price2 = request.getParameter("price2");
		String info5 = request.getParameter("info5");
		
		String imgpath = this.uploadImg(uploadfile);
		Product product = new Product();
		product.setName(name);
		product.setCate(categoryDao.selectBean( " where catelock=0 and id= " +cid));
		product.setPrice1(Double.parseDouble(price1));
		product.setPrice2(Double.parseDouble(price2));
		product.setInfo5(info5);
		product.setImgpath(imgpath);
		product.setCreatetime(new Date());
		productDao.insertBean(product);		
		HttpServletResponse response = ServletActionContext.getResponse();
		response.setCharacterEncoding("gbk");response.setContentType("text/html; charset=gbk");
		response
				.getWriter()
				.print(
	}

	//商品图片上传操作
	public  String  uploadImg(File uploadImg) throws IOException {
	
	
	//查看订单信息操作
	public String orderinfo(){
		HttpServletRequest request = ServletActionContext.getRequest();
		Order order = orderDao.selectBean(" where id= "+request.getParameter("oid"));
		request.setAttribute("order", order);
		this.setUrl("orderinfo.jsp");
		return SU***ESS;
	}
	
	
	
}

public class Util {

	

@Entity
@Table(name="t_product")
public class Product implements Serializable{

	private static final long serialVersionUID = 2429695896963809305L;

	private long id;
	
	private String name ;
	
	private String imgpath;
	
	private double price1;
	
	private double price2;
	
	private Date createtime;
	
	private Category cate; 
	
	private String info5;

	private int xiaoliang;
	
	private int newstuijian;
	
	private int productlock;

	public int getXiaoliang() {
		return xiaoliang;
	}

	public void setXiaoliang(int xiaoliang) {
		this.xiaoliang = xiaoliang;
	}

	@Id
	@GeneratedValue
	public long getId() {
		return id;
	}

	public void setId(long id) {
		this.id = id;
	}

	
	
	//订单列表
	public String orderlist() {
		HttpServletRequest request = ServletActionContext.getRequest();
		String orderid = request.getParameter("orderid");
		String  username = request.getParameter("username");
		String status = request.getParameter("status");
		String time1 = request.getParameter("time1");
		String time2 = request.getParameter("time2");
		
		
		StringBuffer sb = new StringBuffer();
		sb.append(" where ");
	
		if(orderid!=null&&!"".equals(orderid)){
			sb.append("orderid like '%"+orderid.trim()+"%'");
			sb.append(" and ");
			
			request.setAttribute("orderid", orderid);
		}
		
		if(username!=null&&!"".equals(username)){
			sb.append("username like '%"+username.trim()+"%'");
			sb.append(" and ");
			
			request.setAttribute("username", username);
		}
		
		if(status!=null&&!"".equals(status)){
			if("未受理订单".equals(status)){
				sb.append("status =0");
				sb.append(" and ");
			
			}else{
				sb.append("status =1");
				sb.append(" and ");
		
			}
			request.setAttribute("status", status);
		}
		if(time1!=null&&!"".equals(time1)){
			sb.append("createtime >=  '"+time1+"'");
			sb.append(" and ");
		
			request.setAttribute("time1", time1);
		}
		
		if(time2!=null&&!"".equals(time2)){
			sb.append("createtime <  '"+time2+"'");
			sb.append(" and ");
		request.setAttribute("pagerinfo", Pager.getPagerNormal(total, pagesize,
				currentpage, "houtaimethod!productlist", "共有" + total + "条记录"));
		this.setUrl("product/productlist.jsp");
		return SU***ESS;
	}

	//跳转到添加商品页面
	public String productadd() {
		HttpServletRequest request = ServletActionContext.getRequest();
		String where = " where catelock=0  ";
		request.setAttribute("list", categoryDao.selectBeanList(0, 9999, where));
		this.setUrl("product/productadd.jsp");
		return SU***ESS;
	}
	
	

	private File uploadfile;

	public File getUploadfile() {
		return uploadfile;
	}

	public void setUploadfile(File uploadfile) {
		this.uploadfile = uploadfile;
	}
//添加商品操作
	public void productadd2() throws IOException {
		HttpServletRequest request = ServletActionContext.getRequest();
		String name = request.getParameter("name");
		String cid = request.getParameter("cid");
		String price1 = request.getParameter("price1");
		String price2 = request.getParameter("price2");
		String info5 = request.getParameter("info5");
		
		String imgpath = this.uploadImg(uploadfile);
		Product product = new Product();
		product.setName(name);
		product.setCate(categoryDao.selectBean( " where catelock=0 and id= " +cid));
		product.setPrice1(Double.parseDouble(price1));
		product.setPrice2(Double.parseDouble(price2));
		product.setInfo5(info5);
		product.setImgpath(imgpath);
		product.setCreatetime(new Date());
		productDao.insertBean(product);		
		HttpServletResponse response = ServletActionContext.getResponse();
		response.setCharacterEncoding("gbk");response.setContentType("text/html; charset=gbk");
		response
				.getWriter()
				.print(
	}

	//商品图片上传操作
		}else{
			product.setNewstuijian(0);
		}
		productDao.updateBean(product);
		HttpServletResponse response = ServletActionContext.getResponse();
		response.setCharacterEncoding("gbk");response.setContentType("text/html; charset=gbk");
		response
				.getWriter()
				.print(
	}

	
	
	
	
	//订单列表
	public String orderlist() {
		HttpServletRequest request = ServletActionContext.getRequest();
		String orderid = request.getParameter("orderid");
		String  username = request.getParameter("username");
		String status = request.getParameter("status");
		String time1 = request.getParameter("time1");
		String time2 = request.getParameter("time2");
		
		
		StringBuffer sb = new StringBuffer();
		sb.append(" where ");
	
		if(orderid!=null&&!"".equals(orderid)){
			sb.append("orderid like '%"+orderid.trim()+"%'");
			sb.append(" and ");
			
			request.setAttribute("orderid", orderid);
		}
		
		if(username!=null&&!"".equals(username)){
			sb.append("username like '%"+username.trim()+"%'");
			sb.append(" and ");
			
			request.setAttribute("username", username);
		}
			${fn:substring(bean.createtime,0, 10)}
			</td>
			<td height="35">
			${bean.username }
			</td>
			<td height="35">
			货到付款
			</td>
			<td height="35">
			<c:if test="${bean.status==0}">
			提交成功
			</c:if>
			<c:if test="${bean.status==1}">
			发货成功
			</c:if>
			</td>
			<td height="35">
			<a href="####" onclick="orderinfoshow(${bean.id })">查看详情</a>
			</td>
			</tr>
			
			</c:forEach>
<tr >
<td colspan="6">${pagerinfo }</td>
</tr>
</table>

</DIV>

<DIV id=clear_div></DIV></DIV></DIV>

<DIV style="FLOAT: right" class=content_box_right_1>
<form action="index" method="post">
  商品搜索: <input type="text" value="请输入商品名" name="keyword" size="10" class="inputfield" title="email address" onfocus="clearText(this)" onblur="clearText(this)" />
           <input type="submit" name="submit" value="搜索"  />
 </form>

		
	}

	@SuppressWarnings("unchecked")
	public User selectBean(String where) {
		List<User> list = this.getHibernateTemplate().find("from User " +where);
		if(list.size()==0){
			return null;
		}
		return list.get(0);
	}

	public int selectBeanCount(String where) {
		long count = (Long)this.getHibernateTemplate().find("select count(*) from User "+where).get(0);
		return (int)count;
	}

	@SuppressWarnings("unchecked")
	public List<User> selectBeanList(final int start,final int limit,final String where) {
		return (List<User>)this.getHibernateTemplate().executeFind(new HibernateCallback() {
			public Object doInHibernate(final Session session)throws HibernateException, SQLException {				
				List<User> list = session.createQuery("from User "+where)
				.setFirstResult(start)
				.setMaxResults(limit)
				.list();
				return list;
			}
		});
	}

	public void updateBean(User bean) {
		this.getHibernateTemplate().update(bean);
		
	}
	
	
}

@Entity
@Table(name="t_orderitem")
public class OrderItem implements Serializable{

	private static final long serialVersionUID = 3629031007773014380L;

	private long id;
	
                    <form name="myform" action="houtaimethod!login" method="post">
                        <table cellSpacing="0" cellPadding="0" width="100%" border="0" height="143" id="table212">
                          <tr>
                            <td width="13%" height="38" class="top_hui_text"><span class="login_txt">用户名:&nbsp;&nbsp; </span></td>
                            <td height="38" colspan="2" class="top_hui_text"><input name="username" class="editbox4" value="" size="20">                            
						  </td>
                          </tr>
                          <tr>
                            <td width="13%" height="35" class="top_hui_text"><span class="login_txt"> 密 码: &nbsp;&nbsp; </span></td>
                            <td height="35" colspan="2" class="top_hui_text"><input class="editbox4" type="password" size="20" name="password">
                              <img src="images/luck.gif" width="19" height="18"> </td>
                          </tr>
                          <tr>
                            <td height="35" >&nbsp;</td>
                            <td width="20%" height="35" ><input name="Submit" type="submit" class="button" id="Submit" value="登 陆"> </td>
                            <td width="67%" class="top_hui_text"><input name="cs" type="button" class="button" id="cs" value="取 消" onClick="showConfirmMsg1()"></td>
                            <td height="35" ><a href="../">返回首页</a></td>
                          </tr>
                        </table>
                        <br>
                    </form></td>
                  </tr>
                  <tr>
                    <td width="433" height="164" align="right" valign="bottom"><img src="images/login-wel.gif" width="242" height="138"></td>
                    <td width="57" align="right" valign="bottom">&nbsp;</td>
                  </tr>
              </table></td>
            </tr>
          </table>
          </td>
      </tr>
    </table></td>
  </tr>
  <tr>
    <td height="20"><table width="100%" border="0" cellspacing="0" cellpadding="0" class="login-buttom-bg">
      <tr>
        <td align="center"><span class="login-buttom-txt"></span></td>
      </tr>
    </table></td>
  </tr>
</table>
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.***/jsp/jstl/core"%>
<%@ taglib uri="http://java.sun.***/jsp/jstl/functions" prefix="fn"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
	<head>
		<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
		<title>新用户注册</title>
		<%
					+ "'>尾页</a>】");
		}
		return buf.toString();
	}
}

public class OrderItemDaoImpl extends HibernateDaoSupport implements  OrderItemDao{

	public void deleteBean(OrderItem bean) {
		this.getHibernateTemplate().delete(bean);
		
	}

	public void insertBean(OrderItem bean) {
		this.getHibernateTemplate().save(bean);
		
	}

	@SuppressWarnings("unchecked")
	public OrderItem selectBean(String where) {
		List<OrderItem> list = this.getHibernateTemplate().find("from OrderItem " +where);
		if(list.size()==0){
			return null;
		}
		return list.get(0);
			response
					.getWriter()
					.print(
			return null;
		}
	}
	
	
	//查看订单信息操作
	public String orderinfo(){
		HttpServletRequest request = ServletActionContext.getRequest();
		Order order = orderDao.selectBean(" where id= "+request.getParameter("oid"));
		request.setAttribute("order", order);
		this.setUrl("orderinfo.jsp");
		return SU***ESS;
	}
	
	
	
}


<DIV id=clear_div></DIV></DIV></DIV>

<DIV style="FLOAT: right" class=content_box_right_1>
<form action="index" method="post">
  商品搜索: <input type="text" value="请输入商品名" name="keyword" size="10" class="inputfield" title="email address" onfocus="clearText(this)" onblur="clearText(this)" />
           <input type="submit" name="submit" value="搜索"  />
 </form>

<DIV id=c>
</DIV>
</DIV>
<DIV id=orderArea class=content_box_right>
<DIV id=showHot class=content_box_right_2>
</DIV>
<span style="font-size: 20px;color: red;">
热度排行榜:
</span>

<table width="100%"  cellpadding="0" cellspacing="20">
<tr>

<td width="80%">商品</td>
<td width="20%">销量</td>

</tr>

<c:forEach items="${xiaoliangprolist}" var="bean">
<tr>

<td>${bean.name}</td>
<td>${bean.xiaoliang}</td>

</tr>
</c:forEach>

</table>
<a href="manage/login.jsp">管理后台</a>
</DIV>
</BODY></HTML>

<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>

function registershow(){
		window.open("register.jsp", null,
		'dialogWidth:700px;dialogHeight:500px;help:no;unadorned:no;resizable:no;status:no;scroll:no');
	}
	
function productshow(pid){
		var now = new Date(); 
		var t = now.getTime()+''; 
		window.open("qiantaimethod!product?pid="+pid+"&t="+t, null,
		'dialogWidth:700px;dialogHeight:700px;help:no;unadorned:no;resizable:no;status:no;scroll:yes');
	}
function cartaddshow(pid){
		var now = new Date(); 
		var t = now.getTime()+''; 
		window.open("qiantaimethod!cartadd?pid="+pid+"&t="+t, null,
		'dialogWidth:300px;dialogHeight:100px;help:no;unadorned:no;resizable:no;status:no;scroll:no');
	}
function orderinfoshow(oid){
		var now = new Date(); 
		var t = now.getTime()+''; 
		window.open("qiantaimethod!orderinfo?oid="+oid+"&t="+t, null,
		'dialogWidth:700px;dialogHeight:500px;help:no;unadorned:no;resizable:no;status:no;scroll:yes');
		
	}

</script>

</HEAD>
<BODY>
<DIV class=public_container><LINK rel=stylesheet type=text/css 
href="files/new.css"><LINK rel=stylesheet 
type=text/css href="files/jquery.loadmask.css">

<!--header_box start-->
<DIV class="header_box clearfix">
<H1 class=kfcLogo><span style="font-size: 40px;color: #f4a431;">网上书店</span></H1>
<DIV class=headLeft>
<DIV class=tfav> </DIV>
<P><SPAN>欢迎网上书店! Wel***e to order online!</SPAN></P>
<UL class=clearfix>
  <LI class=m1><A href="."><STRONG>首页</STRONG></A></LI>
  <LI class=m2><A href="qiantaimethod!cart"><STRONG>我的购物车</STRONG></A></LI>
  <LI class=m3><A href="qiantaimethod!order"><STRONG>我的订单</STRONG></A></LI>
  <LI class=m4><A href="#" onclick="registershow()"><STRONG>用户注册</STRONG></A></LI>
  <c:if test="${user==null}"> <LI class=m5><A href="qiantaimethod!login"><STRONG>用户登录</STRONG></A></LI></c:if>
  <c:if test="${user!=null}"> <LI class=m5><A href="qiantaimethod!loginout"><STRONG>用户退出</STRONG></A></LI></c:if>
  </UL></DIV></DIV>
<DIV id=clear_div></DIV><!--content_box start-->
	public void setDrop(boolean drop) {
		this.drop = drop;
	}
	
	
}

public interface OrderItemDao  {
	
	
	
	public void insertBean(OrderItem bean);
	
	public void deleteBean(OrderItem bean);
	
	public void updateBean(OrderItem bean);

	public OrderItem selectBean(String where);
	
	public List<OrderItem> selectBeanList(final int start, final int limit,final String where);
	
	public int selectBeanCount(final String where);
	
	
}

	public void setDrop(boolean drop) {
		this.drop = drop;
	}
	
	
}

public interface OrderItemDao  {
	
	
	
	public void insertBean(OrderItem bean);
	
	public void deleteBean(OrderItem bean);
	
	public void updateBean(OrderItem bean);

	public OrderItem selectBean(String where);
	
	public List<OrderItem> selectBeanList(final int start, final int limit,final String where);
	
	public int selectBeanCount(final String where);
	
	
}


</DIV>

<DIV id=clear_div></DIV></DIV></DIV>

<DIV style="FLOAT: right" class=content_box_right_1>
<form action="index" method="post">
  商品搜索: <input type="text" value="请输入商品名" name="keyword" size="10" class="inputfield" title="email address" onfocus="clearText(this)" onblur="clearText(this)" />
           <input type="submit" name="submit" value="搜索"  />
 </form>

<DIV id=c>
</DIV>
</DIV>
<DIV id=orderArea class=content_box_right>
<DIV id=showHot class=content_box_right_2>
</DIV>
<span style="font-size: 20px;color: red;">
热度排行榜:
</span>

<table width="100%"  cellpadding="0" cellspacing="20">
<tr>

<td width="80%">商品</td>
<td width="20%">销量</td>

</tr>

<c:forEach items="${xiaoliangprolist}" var="bean">
<tr>

<td>${bean.name}</td>
<td>${bean.xiaoliang}</td>

</tr>
</c:forEach>

</table>
<a href="manage/login.jsp">管理后台</a>
</DIV>
</BODY></HTML>

	if (document.getElementById('truenameid').value=="")
	{
		alert("真实姓名不能为空");
		return false;
	}
	if (document.getElementById('addressid').value=="")
	{
		alert("地址不能为空");
		return false;
	}
	if (document.getElementById('phoneid').value=="")
	{
		alert("手机不能为空");
		return false;
	}
	
	valid=/^0?1[3,5,8][0,1,2,3,4,5,6,7,8,9]\d{8}$/;  
	if(!valid.test(document.getElementById('phoneid').value)){
		alert("请输入正确的手机格式");
		return false;
	}
	
	if (document.getElementById('emailid').value=="")
	{
		alert("email不能为空");
		return false;
	}
 

	var reg = new RegExp('^[a-zA-Z0-9]+@[a-zA-Z0-9]+.[a-z][a-z.]{2,8}$');

	if(!reg.test(document.getElementById('emailid').value)){
		alert("请输入正确的email格式");
		return false;
	}
	if (document.getElementById('qqid').value=="")
	{
		alert("qq不能为空");
		return false;
	}
	valid = /^\d{1,20}$/;
	if(!valid.test(document.getElementById('qqid').value)){
		alert("请输入正确的qq格式");
		return false;
	}
	
	doRequestUsingPOSTregister();
	
}

function createQueryStringregister(){
	//必须两次编码才能解决中文问题
	var username = encodeURI(encodeURI($("#usernameid").val()));
	}
	
	//用户注册操作
	public void register() throws Exception{
		HttpServletRequest request = ServletActionContext.getRequest();
		
		HttpServletResponse response = ServletActionContext.getResponse();
		
		User user = new User();
		
		user.setUsername(java.***.URLDecoder.decode(request.getParameter("username"), "utf-8"));
		
		user.setPassword(request.getParameter("password"));
		
		user.setTruename(java.***.URLDecoder.decode(request.getParameter("truename"), "utf-8"));
		
		user.setAddress(java.***.URLDecoder.decode(request.getParameter("address"), "utf-8"));
		
		user.setPhone(java.***.URLDecoder.decode(request.getParameter("phone"), "utf-8"));
		
		user.setEmail(java.***.URLDecoder.decode(request.getParameter("email"), "utf-8"));
		
		user.setQq(java.***.URLDecoder.decode(request.getParameter("qq"), "utf-8"));
		
		user.setCreatetime(new Date());
		
		User u = userDao.selectBean(" where username='"+user.getUsername()+"'");
		
		if(u==null){
			userDao.insertBean(user);
			response.setCharacterEncoding("utf-8");
			response.getWriter().write("注册新用户成功!您的用户名"+user.getUsername()+",请妥善保管!");
			}else{
				response.setCharacterEncoding("utf-8");
				response.getWriter().write("该用户名已经存在,请重新注册!");
		}
	}
	
	
	//跳转到用户登录页面
	public String login(){
		HttpServletRequest request = ServletActionContext.getRequest();
		List<Category> catelist = categoryDao.selectBeanList(0, 9999, " where catelock=0 ");
		request.setAttribute("topcatelist",catelist );
		request.setAttribute("xiaoliangprolist",productDao.selectBeanList(0, 15, " where productlock=0 order by xiaoliang desc "));//销量排行商品列表
		this.setUrl("login.jsp");
		return SU***ESS;
	}











转载请说明出处内容投诉
CSS教程网 » 基于javaweb和mysql的ssh网上书店图书商城(java+ssh+mysql+jsp)

发表评论

欢迎 访客 发表评论

一个令你着迷的主题!

查看演示 官网购买