大三课设 - Java、bootstrap、jQuery、MVC、MySQL、EL、JSTL 交易网站、二手、校园、实时交互、ECharts ---- 首页内容

页面内容:

大三课设 - Java、bootstrap、jQuery、MVC、MySQL、EL、JSTL 交易网站、二手、校园、实时交互、ECharts ---- 首页内容_第1张图片大三课设 - Java、bootstrap、jQuery、MVC、MySQL、EL、JSTL 交易网站、二手、校园、实时交互、ECharts ---- 首页内容_第2张图片

  1. 登录注册(记住密码)https://blog.csdn.net/n20164206199/article/details/86218384
  2. 搜索关键字点击显示到搜索框,搜索跳转页面  https://blog.csdn.net/n20164206199/article/details/86219679
  3. 发布二货跳转到添加界面
  4. 首页图片内容、分页的获取与显示  : https://mp.csdn.net/postedit/86216843
  5. 点击向上的手跳到顶部

 index.jsp

<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
    <%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>



    
    
    
    
    
    
    
    
    
    
    
    大学生二手交易网站
    
    





¥${photo.price }
${photo.ptitle }

第 ${pBean.currentPage }/${pBean.totalPage } 页 每页显示 ${pBean.pageSize } 条 总记录 ${pBean.totalSize } 条
123456798;
说明
欢迎进入网站 大学生二手网,淘二手,大学生二手交易网,淘二手网,大学生二手交易平台,大学生二手市场,校园二手街,淘二淘,大学城二手网,二手交易网 淘二淘-大学生二手网是一个为全国高校在校大学生提供的一个安全、方便、快捷的二手闲置物品交易平台和校园二手信息发布网站。 淘二淘-大学生二手网 是一个为全国高校在校大学生提供的一个安全、方便、快捷的二手闲置物品交易平台和校园二手信息发布网站。
名称 城市 邮编
Tanmay 湖南 560001
Sachin 湖北 400003
Uma 全国 411027





step1:先进入firststep.jsp 

<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>




Insert title here






steptwo:进入Servlet 获取 index.jsp中的内容并重定向

package cn.trade.servlet;

import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import cn.trade.model.PhotoBean;
import cn.trade.serviceimp.PhotoBeanServiceImp;

/**
 * Servlet implementation class IndexPageServlet
 */
@WebServlet("/IndexPageServlet")
public class IndexPageServlet extends HttpServlet {
	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		doPost(request, response);
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		int currentPage = Integer.parseInt(request.getParameter("currentPage"));
		
		PhotoBean pBean = new PhotoBeanServiceImp().findByPage(currentPage);
		
		request.getSession().setAttribute("pBean", pBean);
		
		request.getRequestDispatcher("index.jsp").forward(request, response);
		
	}

}

 stepthree:进入Service层 获取页面相关信息

package cn.trade.serviceimp;

import java.util.List;

import cn.trade.daoimp.AdvertDaoImp;
import cn.trade.daoimp.PhotoDaoImp;
import cn.trade.model.Advert;
import cn.trade.model.Photo;
import cn.trade.model.PhotoBean;
import cn.trade.service.PhotoBeanService;

public class PhotoBeanServiceImp implements PhotoBeanService {

	@Override
	public PhotoBean findAll() {
		// TODO Auto-generated method stub
		//更新全部商品信息
		new PhotoDaoImp().Del();
		new PhotoDaoImp().updatePhoto();
		
		//获取轮播广告的信息
		List alist = new AdvertDaoImp().findAll();
		int adsize = new AdvertDaoImp().advertSize();
		
		
		List plist = new PhotoDaoImp().findAll();
		int psize = new PhotoDaoImp().photoSize();
				
		
		PhotoBean pb = new PhotoBean();
		pb.setPlist(plist);
		pb.setAlist(alist);
		pb.setAdsize(adsize);
		pb.setPsize(psize);
		
		return pb;
	}
	
	public PhotoBean findByPage(int currentPage) {
		//更新全部商品信息
		new PhotoDaoImp().Del();
		new PhotoDaoImp().updatePhoto();
		
		//获取轮播广告的信息
		List alist = new AdvertDaoImp().findAll();
		int adsize = new AdvertDaoImp().advertSize();
		
		PhotoBean pb = new PhotoBean();
		
		//获取分页
		List pagelist = new PhotoDaoImp().findByPage(currentPage);
		
		//页面相关的信息
		int totalSize = new PhotoDaoImp().photoSize();
		int pageSize = PhotoDaoImp.PAGESIZE;
		int totalPage = totalSize%pageSize>0? totalSize/pageSize+1:totalSize/pageSize;
		pb.setCurrentPage(currentPage);
		pb.setPageSize(pageSize);
		pb.setTotalPage(totalPage);
		pb.setTotalSize(totalSize);		
		
		pb.setPlist(pagelist);
		pb.setAlist(alist);
		pb.setAdsize(adsize);
		
		return pb;
	}

}

step five: 进入Dao层获取数据库信息(我是分页显示、此处将分页的代码贴出)

package cn.trade.daoimp;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.Delayed;

import cn.trade.dao.PhotoDao;
import cn.trade.model.Photo;
import cn.trade.util.DBUtil;

public class PhotoDaoImp implements PhotoDao{
	public static final int PAGESIZE = 9;
	@Override
	public List findAll() {
		// TODO Auto-generated method stub
		List list = new ArrayList<>();
		Connection conn = DBUtil.getConn();
		String sql="SELECT * FROM tb_prophoto";
		try {
			PreparedStatement pstmt = conn.prepareStatement(sql);
			ResultSet rs = pstmt.executeQuery();
			while(rs.next()){
				Photo pho = new Photo();
				pho.setPid(rs.getInt("pid"));
				pho.setPtitle(rs.getString("ptitle"));
				pho.setImgress(rs.getString("imgress"));
				pho.setPrice(rs.getDouble("price"));
				list.add(pho);
			}
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return list;
	}

	@Override
	public int photoSize() {
		// TODO Auto-generated method stub
		Connection conn = DBUtil.getConn();
		String sql="SELECT COUNT(*) FROM tb_prophoto";
		try {
			PreparedStatement pstmt = conn.prepareStatement(sql);
			ResultSet rs = pstmt.executeQuery();
			while(rs.next()){
				return rs.getInt(1);
			}
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return 0;
	}

	@Override
	public void delPhoto(int pid) {
		// TODO Auto-generated method stub
		Connection conn = DBUtil.getConn();
		String sql = "DELETE FROM tb_photo WHERE pid =?";
		try {
			PreparedStatement pstmt = conn.prepareStatement(sql);
			pstmt.setInt(1, pid);
			pstmt.executeUpdate();
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		};
	}
	
	public void Del(){
		Connection conn = DBUtil.getConn();
		String sql = "DELETE FROM tb_prophoto";
		try {
			PreparedStatement pstmt = conn.prepareStatement(sql);
			pstmt.executeUpdate();
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		};
	}
	@Override
	public void updatePhoto() {
		// TODO Auto-generated method stub
		Connection conn = DBUtil.getConn();
		String sql =" INSERT INTO tb_prophoto(pid,ptitle,imgress,price)" 
				+	" SELECT pid,ptitle,imgress,outprice FROM tb_product p";
		try {
			PreparedStatement pstmt = conn.prepareStatement(sql);
			pstmt.executeUpdate();
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		};
	}

	@Override
	public List findByPage(int currentPage) {
		// TODO Auto-generated method stub
		List list = new ArrayList<>();
		Connection conn = DBUtil.getConn();
		String sql="SELECT * FROM tb_prophoto LIMIT ?,?";
		try {
			PreparedStatement pstmt = conn.prepareStatement(sql);
			pstmt.setInt(1, (currentPage-1)*PAGESIZE);
			pstmt.setInt(2, PAGESIZE);
			ResultSet rs = pstmt.executeQuery();
			while(rs.next()){
				Photo pho = new Photo();
				pho.setPid(rs.getInt("pid"));
				pho.setPtitle(rs.getString("ptitle"));
				pho.setImgress(rs.getString("imgress"));
				pho.setPrice(rs.getDouble("price"));
				list.add(pho);
			}
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return list;
	}

}

 

实现从数据库获取信息并返回显示到首页 

你可能感兴趣的:(javaweb)