2020-03-28
Version:1.0 StartHTML:000000201 EndHTML:000015618 StartFragment:000008720 EndFragment:000015580 StartSelection:000008720 EndSelection:000015580 SourceURL://www.greatytc.com/p/6588750ab283 自行设计数据库、表结构,插入测试数据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<MyUser> list = myuserModel.findAll(); 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<MyUser> findAll() throws SQLException{ QueryRunner queryRunery = new QueryRunner(Utils.getDataSource()); List<MyUser> list = queryRunery.query("select * from MyUser",new BeanListHandler<MyUser>(MyUser.class)); 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" %><!DOCTYPE html><html><head><meta charset="UTF-8"><title>Insert title here</title></head><body><h1>商品信息显示页面</h1><table border="1" width="600"><tr> <td>商品名称</td> <td>商品价钱</td> <td>商品总数量</td> <td>商品上架时间</td> </tr> <c:forEach var="MyUser" items="${ list }"> <tr> <td>${ MyUser.gname }</td> <td>${ MyUser.price }</td> <td>${ MyUser.number }</td> <td>${ MyUser.gdate}</td> </tr> </c:forEach> <c:set value="test" var="name" scope="page"> <c:if test="${ status.count % 3 == 0 }"> <font color="transparent">${ test }</font> </c:if> <c:if test="${ status.count % 3 != 0 }"> ${ test } </c:if></c:set> </table></body></html><%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%> <%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %><!DOCTYPE html><html><head><meta charset="UTF-8"><title>Insert title here</title></head><body> <td class="a-span10"> <a class="a-link-normal" title="7% 的评论都有 2 颗星" href="https://www.amazon.cn/product-reviews/B07DGSQ6D3/ref=acr_search_hist_2?ie=UTF8&filterByStar=two_star&reviewerType=all_reviews#reviews-filter-bar"> <div class="a-meter" aria-label="7%"><div name="a-meter-bar a-meter-filled" page="width: 7%;"></div></div> </a> </td> <hr class="a-spacing-large a-divider-normal"><div class="a-section a-spacing-base a-text-center"><a class="a-size-base a-link-emphasis" href="https://www.amazon.cn/product-reviews/B07DGSQ6D3">查看全部28 条商品评论</a></div><div class="a-arrow-border" style="left: 177px;"><div class="a-arrow"></div></div></div><span tabindex="0" class="a-popover-end a-popover-a11y-offscreen"> </span></div></body></html>
©著作权归作者所有,转载或内容合作请联系作者
- 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
- 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
- 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...