JSP 页面显示sql中数据。el

存储数据库字段。

package Bean;

/**
* Created by Administrator on 2017/5/24.
*/
public class info {
private String id;
private String user;
private String contain;
private String date;
private String time; public String getId() {
return id;
} public void setId(String id) {
this.id = id;
} public String getUser() {
return user;
} public void setUser(String user) {
this.user = user;
} public String getContain() {
return contain;
} public void setContain(String contain) {
this.contain = contain;
} public String getDate() {
return date;
} public void setDate(String date) {
this.date = date;
} public String getTime() {
return time;
} public void setTime(String time) {
this.time = time;
}
}

处理逻辑

package Dao;

import Bean.info;
import DbConn.DbConn;
import SQL.SQL; import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List; /**
* Created by Administrator on 2017/5/24.
*/
public class Serach {
public List<info> seacha(){
List<info> list = new ArrayList<info>();
Connection conn = DbConn.getConnection();
try {
PreparedStatement ps = conn.prepareStatement(new SQL().getSelectAll());
ResultSet rs = ps.executeQuery();
while (rs.next()){
info info = new info();
info.setId(rs.getString(1));
info.setUser(rs.getString(2));
info.setContain(rs.getString(3));
info.setDate(rs.getString(4));
info.setTime(rs.getString(5));
list.add(info);
}
} catch (SQLException e) {
e.printStackTrace();
}
return list;
}
}

jsp页面显示

<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ page import="Dao.Serach" %>
<%@ page import="java.util.List" %>
<%--
Created by IntelliJ IDEA.
User: Administrator
Date: 2017/5/24
Time: 21:01
To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
<link rel="stylesheet" href="css/mdui.min.css">
<script src="js/mdui.min.js" type="text/javascript" charset="utf-8"></script>
<script src="//mdui-org.b0.upaiyun.com/source/dist/js/mdui.min.js"></script>
<script src="//mdui-org.b0.upaiyun.com/docs/assets/holder-2.9.4/holder.min.js"></script>
<title>$Title$</title>
</head>
<body class="mdui-top-padding" style="background-image: url(/img/img.jpg);background-attachment: fixed;background-repeat: no-repeat;background-size: cover">
<%
Serach ser = new Serach();
List ls = ser.seacha();
request.getSession().setAttribute("cuslist",ls);
%> <div class="mdui-container mdui-color-white-0">
<div class="mdui-container mdui-appbar-fixed mdui-zindex">
<form action="/insert" method="post" class="mdui-color-grey-200">
<div class="mdui-textfield mdui-textfield-floating-label">
<i class="mdui-icon material-icons"></i>
<label class="mdui-textfield-label">Message</label>
<textarea class="mdui-textfield-input" name="message" maxlength="222"></textarea>
</div>
<div>
<button class="mdui-btn mdui-btn-raised mdui-ripple mdui-color-theme-accent mdui-btn-block">发表说说</button>
</div>
</form>
</div>
<c:forEach var="cus" items="${cuslist}">
<div class="mdui-card mdui-m-t-5 mdui-color-grey-200">
<!-- 卡片的标题和副标题 -->
<div class="mdui-card-primary ">
<div class="mdui-chip">
<img class="mdui-chip-icon" src="img/head.png"/>
<span class="mdui-chip-title mdui-card-primary-title">${cus.user}</span>
</div>
<div class="mdui-card-primary-subtitle">${cus.date} <i class="mdui-icon material-icons"></i>${cus.time}</div>
</div>
<!-- 卡片的内容 -->
<div class="mdui-card-content">${cus.contain}</div>
<!-- 卡片的按钮 -->
<%--<div class="mdui-card-actions">--%>
<%--<button class="mdui-btn mdui-ripple"></button>--%>
<button class="mdui-btn mdui-ripple" name=${cus.id}>删除</button>
<button class="mdui-btn mdui-btn-icon mdui-float-right"><i class="mdui-icon material-icons"></i></button>
<%--</div>--%>
</div>
</c:forEach>
</div>
<div style="width: auto;height: 100px"></div>
</body>
</html>
上一篇:【转】 bio 与块设备驱动


下一篇:升级Win2010后, 打开SQL2008 附加数据库提示 5120错误