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 pagelogin.jsp
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
My JSP 'login.jsp' starting pageloginSuccess.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 pageregisterSuccess.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购买成功
完了,谢谢观赏
我觉得有一个地方的效率不高,我们交流交流