自行设计数据库、表结构,插入测试数据
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;
import com.MyUser.model.MyUserModel;
/**
* Servlet implementation class MyUserServlet
*/
@WebServlet("/MyUserServlet")
public class MyUserServlet extends HttpServlet {
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
try {
MyUserModel myuserModel = new MyUserModel();
List
request.setAttribute("list", list);
request.getRequestDispatcher("/jsp/list.jsp").forward(request, response);
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
doGet(request, response);
}
}
package com.MyUser.domain;
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;
}
}
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
QueryRunner queryRunery = new QueryRunner(Utils.getDataSource());
List
return list;
}
}
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
"UTF-8">
商品信息显示页面
商品名称 | 商品价钱 | 商品总数量 | 商品上架时间 |
${ MyUser.gname } | ${ MyUser.price } | ${ MyUser.number } | ${ MyUser.gdate} |
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
"UTF-8">
"a-spacing-large a-divider-normal">