目录
1.创建一个项目中的src--main-java--com.csi.eshop 下有三个包:
Session消失的几种方式:客户端和服务器端
- 客户端
- 如果关闭浏览器,在重新打开的时候会导致产生一个新的cookie 同时就会产生一个新的sessionId对象,对于用户来讲,相当于一个新的用户。之前的session就消失了
- 关闭浏览器之前的session并没有消失,会保留在服务器中知道过期为止
- 服务器端
- session超时,一段时间之内没有和浏览器做交互的话,此刻的状态就是未交互状态,当时长超过默认的时间或者使用者自定义的时间的 会导致session消失
- 用户点击了注销按钮之后,此时的注销按钮调用了session.invalidate()方法,导致当前用户session 注销
- 服务器待机或者关闭服务资源, 或者是由于遇到严重错误的时候 也会导致session消失。
1.先编写domain
package com.csi.eshop.domain;
import java.io.Serializable;
public class ProductBrand implements Serializable {
private Integer id;
private String brand_name;
private String brand_desc;
private String brand_logo;
public Integer getId() {
return id;
}
public void setId(Integer id) {
this.id = id;
}
public String getBrand_name() {
return brand_name;
}
public void setBrand_name(String brand_name) {
this.brand_name = brand_name;
}
public String getBrand_desc() {
return brand_desc;
}
public void setBrand_desc(String brand_desc) {
this.brand_desc = brand_desc;
}
public String getBrand_logo() {
return brand_logo;
}
public void setBrand_logo(String brand_logo) {
this.brand_logo = brand_logo;
}
}
2.编写dao 中的 接口
package com.csi.eshop.dao;
import com.csi.eshop.domain.Product;
import com.csi.eshop.domain.ProductBrand;
import java.sql.SQLException;
import java.util.List;
public interface ProductBrandDao {
List<ProductBrand> list() throws SQLException;
List<Product> findId(int brand_id) throws SQLException;
}
2.1编写dao 中的 impl
package com.csi.eshop.dao.impl;
import com.csi.eshop.dao.ProductBrandDao;
import com.csi.eshop.domain.Product;
import com.csi.eshop.domain.ProductBrand;
import com.csi.eshop.utils.JDBCUtils;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;
public class ProductBrandDaoImpl extends JDBCUtils implements ProductBrandDao {
@Override
public List<ProductBrand> list() throws SQLException {
final String SQL = "SELECT * FROM easybuy_brand" ;
Connection connection = this.getConnection() ;
PreparedStatement ps = connection.prepareStatement(SQL);
ResultSet rs = ps.executeQuery();
List<ProductBrand> productBrands = new ArrayList<>() ;
ProductBrand productBrand = null ;
while (rs.next()){
productBrand = new ProductBrand() ;
productBrand.setId(rs.getInt("id"));
productBrand.setBrand_name(rs.getString("brand_name"));
productBrand.setBrand_desc(rs.getString("brand_desc"));
productBrand.setBrand_logo(rs.getString("brand_logo"));
productBrands.add(productBrand);
}
release(rs,ps,connection)