java ee简易购物车_发一个struts2+hibernate3实现的简单购物车程序

figo.register.dao

这个包是用hibernate3处理后台

User.java

package figo.register.dao;

import java.util.Set;

public class User {

private String uid;

private String username;

private String password;

private int age;

private Set product;

public Set getProduct() {

return product;

}

public void setProduct(Set product) {

this.product = product;

}

public String getUid() {

return uid;

}

public void setUid(String uid) {

this.uid = uid;

}

public String getUsername() {

return username;

}

public void setUsername(String username) {

this.username = username;

}

public String getPassword() {

return password;

}

public void setPassword(String password) {

this.password = password;

}

public int getAge() {

return age;

}

public void setAge(int age) {

this.age = age;

}

}

User.hbm.xml

/p>

"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">

Product.java

package figo.register.dao;

public class Product {

private String pid;

private String productname;

private int productcount;

private int allprice;

private User user;

public User getUser() {

return user;

}

public void setUser(User user) {

this.user = user;

}

public String getPid() {

return pid;

}

public void setPid(String pid) {

this.pid = pid;

}

public String getProductname() {

return productname;

}

public void setProductname(String productname) {

this.productname = productname;

}

public int getProductcount() {

return productcount;

}

public void setProductcount(int productcount) {

this.productcount = productcount;

}

public int getAllprice() {

return allprice;

}

public void setAllprice(int allprice) {

this.allprice = allprice;

}

}

Product.hbm.xml

/p>

"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">

UserOperation.java

package figo.register.dao;

import java.util.List;

import org.hibernate.Query;

import org.hibernate.Session;

import org.hibernate.cfg.Configuration;

public class UserOperation {

private Session session;

public UserOperation()

{

this.session= new Configuration().configure().buildSessionFactory().openSession();

}

public void save(User user)

{

this.session.save(user);

this.session.beginTransaction().commit();

}

public void save(Product p)

{

this.session.save(p);

this.session.beginTransaction().commit();

}

public User QueryByUsername(String username)

{

String hql="from User as u where u.username=?";

Query q = session.createQuery(hql);

q.setString(0, username);

List l=q.list();

User user = null;

if(l.size()>0)

{

user =(User)l.get(0);

}

return user;

}

public void update(User user)

{

this.session.update(user);

this.session.beginTransaction().commit();

}

public void update(Product p)

{

this.session.update(p);

this.session.beginTransaction().commit();

}

}

下面就是前台展示层的内容,在web-Root下

建立jsp文件

index.jsp

String path = request.getContextPath();

String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";

%>

My JSP 'index.jsp' starting page

登陆

注册

login.jsp

String path = request.getContextPath();

String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";

%>

My JSP 'login.jsp' starting page

loginSuccess.jsp

String path = request.getContextPath();

String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";

%>

My JSP 'loginSuccess.jsp' starting page

登陆成功    

您登陆的用户名为:

String username=request.getParameter("username");

session.setAttribute("username",username);

%>

 

去商店购物

register.jsp

String path = request.getContextPath();

String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";

%>

My JSP 'register.jsp' starting page

registerSuccess.jsp

String path = request.getContextPath();

String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";

%>

My JSP 'registerSuccess.jsp' starting page

注册成功

注册基本信息:

用户名:

密码:

年龄:

shop.jsp

String path = request.getContextPath();

String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";

%>

My JSP 'shop.jsp' starting page

商品名

商品描述

价格

钢笔

最好的钢笔

$20

购买一支

圆珠笔

最好的圆珠笔

$25

购买一支

shopSuccess.jsp

String path = request.getContextPath();

String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";

%>

My JSP 'shopSuccess.jsp' starting page

购买成功

返回继续购买

完了,谢谢观赏

我觉得有一个地方的效率不高,我们交流交流

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值