zoukankan      html  css  js  c++  java
  • jsp+jstl从数据库读取数据显示在网页上

    笔记

     
     
     
    <%@ page language="java" contentType="text/html; charset=UTF-8"
        pageEncoding="UTF-8"%>
    <%@ page import="java.io.*,java.util.*,java.sql.*"%>
    
    <%@ page import="javax.servlet.http.*,javax.servlet.*" %>
    <%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
    <%@ taglib uri="http://java.sun.com/jsp/jstl/sql" prefix="sql"%>
    <!DOCTYPE html>
    <html>
            <head>
            <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
            <title>JSP Page</title>
            <style type="text/css">
    div {
        background-color: #c3c3c36e;
         300px;
        float:left;
        margin-right:20px;
      margin-left:10px;
    }
    
    p {
     line-height :1.8em;
     font-size:14px;
    }
        </style>
        </head>
        <body>
        <sql:setDataSource var="snapshot"         driver="com.mysql.jdbc.Driver"
             url="jdbc:mysql://localhost:3306/test_ll?    useUnicode=true&characterEncoding=utf-8"
             user="root"  password="root"/>
        <sql:query dataSource="${snapshot}" var="result">
      SELECT * from table1;
    </sql:query>
      <sql:query dataSource="${snapshot}" var="result1">
        SELECT * from table2;
       </sql:query>
      <sql:query dataSource="${snapshot}" var="result2">
        SELECT * from table3;
      </sql:query>
     
    <div id="row1">
      <p>
        <tr>
           <th></th>
        </tr>
    <c:forEach var="row" items="${result.rows}">
       &nbsp;<img src="img/icon1.png">&nbsp;${row.content}<br/>
    </c:forEach>
      </p>
    </div>
    <div id="row2">
      <p>
    <tr>
       <th></th>
    </tr>
    <c:forEach var="row" items="${result1.rows}">
      &nbsp;<img src="img/icon1.png">&nbsp;${row.content}<br/>
    </c:forEach>
      </p>
    </div>
    <div id="row3">
      <p>
    <tr>
       <th></th>
    </tr>
    
    <c:forEach var="row" items="${result2.rows}">
       &nbsp;<img src="img/icon1.png">&nbsp;${row.content}<br/>
    </c:forEach>
      </p>
    </div>
    
      </body>
    </html> 
  • 相关阅读:
    锤炼自己,即便是铁,也要是铁中的佼佼者。
    数据库简单学习
    英雄总结
    强化肖龙
    神兽世界
    魔豆魔豆
    硬链接和软连接的区别
    深拷贝和浅拷贝的区别
    C++程序员(终身学习)
    矫健《圣徒》读后感
  • 原文地址:https://www.cnblogs.com/shanghuliu/p/10383626.html
Copyright © 2011-2022 走看看