2020-03-25

package com.MyUser.controller;

import java.io.IOException;

import java.util.List;

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 com.MyUser.domain.MyUser;

/**

* Servlet implementation class MyUserServlet

*/

@WebServlet("/MyUserServlet")

public class MyUserServlet extends HttpServlet {

protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

  try {

  MyUser myuserModel = new MyUser();

  List list = myuserModel.findAll();

   

  request.setAttribute("list", list);

  request.getRequestDispatcher("/jsp/list.jsp").forward(request, response);

   

   

  }catch(Exception e) {

  e.printStackTrace();

  }

}

protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

doGet(request, response);

}

}


package com.MyUser.domain;

import java.util.List;

public class MyUser {

    private Integer gname;

    private String price;

    private String number;

    private Integer gdate;

public Integer getGname() {

return gname;

}

public void setGname(Integer gname) {

this.gname = gname;

}

public String getPrice() {

return price;

}

public void setPrice(String price) {

this.price = price;

}

public String getNumber() {

return number;

}

public void setNumber(String number) {

this.number = number;

}

public Integer getGdate() {

return gdate;

}

public void setGdate(Integer gdate) {

this.gdate = gdate;

}

public List findAll() {

// TODO Auto-generated method stub

return null;

}

   

   

}


package com.MyUser.model;

import java.sql.SQLException;

import java.util.List;

import org.apache.commons.dbutils.QueryRunner;

import org.apache.commons.dbutils.handlers.BeanListHandler;

import com.MyUser.Utils.Utils;

import com.MyUser.domain.MyUser;

public class myuserModel {

    public List findAll() throws SQLException{

    QueryRunner queryRunery = new QueryRunner(Utils.getDataSource());

    List list = queryRunery.query("select * from student",new BeanListHandler(MyUser.class));

        return list;

    }

}


<%@ page language="java" contentType="text/html; charset=ISO-8859-1"

    pageEncoding="UTF-8"%>

<%@ taglib uri="http://java.sun.com/jstl/core_rt" prefix="c" %>

Insert title here

商品信息显示页面

 

 

 

 

 

 

 

 

商品名称 商品价钱 商品总数量 商品上架时间
${ myuser.gname } ${ myuser.price } ${ myuser.number } ${ myuser. gdate}

你可能感兴趣的:(2020-03-25)