`
txf2004
  • 浏览: 6877549 次
  • 性别: Icon_minigender_1
  • 来自: 上海
社区版块
存档分类
最新评论

JSTL连接数据库sql

阅读更多
<%@page import="java.text.SimpleDateFormat"%>
<%@ page language="java" contentType="text/html; charset=UTF-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/sql" prefix="sql" %>
<%@ page import="java.util.Date" %>
<%
String path = request.getContextPath();
String basePath = request.getScheme() + "://"
+ request.getServerName() + ":" + request.getServerPort()
+ path + "/";
%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
</head>
<body>

<sql:setDataSource dataSource="jdbc:mysql://localhost:3306/test?user=root&password=518"
var="dataSource" scope="application"
/>
<sql:query var="query1" sql="select * from person" dataSource="${dataSource }" scope="application"/>
<table border="1" bgcolor="#EEE0E5" width="200">
<tbody><tr>
<td>&nbsp;ID</td>
<td>&nbsp;Name</td>
<td>&nbsp;Password</td></tr>


<c:forEach items="${query1.rows }" var="ps">
<tr>
<td>&nbsp;${ps.id }</td>
<td>&nbsp;${ps.name }</td>
<td>&nbsp;${ps.password }</td></tr>
</c:forEach>
</tbody></table>
</body>
</html>
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics