我收到一个空的 html/jsp 表,没有提取数据 [英] I'm receiving an empty html/jsp table with no data extracted

查看:67
本文介绍了我收到一个空的 html/jsp 表,没有提取数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

四天前我在同一个论坛上发帖寻求解决方案,但我一直在寻找任何解决方案,但徒劳无功.我真的很累,因为我无法继续掌握 JSP,这对我 2014 年的 Web 编程计划来说是一个非常大的包裹.我是 JSP 和数据库访问的新手……所以我请求您的帮助.

I made a post four days back on this same forum seeking for a solution, but I have been checking for any solutions but in vain. I'm really stack as I can't continue mastering JSP which is a very big parcel for my 2014 plan of web programming. I'm new to JSP and database access ... so I'm requesting for your help.

问题:
我有一个简单的 MySQL 数据库,并设计了一个 JSP 页面来显示从数据库中提取的数据.我通过命令行尝试并测试了它,是的,数据被完美提取.然而,返回的 JSP 页面显示一个空的 html 表,其中包含四个列标题,类似于下面的内容:

SELECT * from Employees;  
ID   Age  First Name  Last Name 

以下是数据库信息:

database - 'EMP'.  
table -  'Employees'.  
Columns; id; age; first; last.  
data;   100; 28; Zaid; Khan.      
password - 'password'  

以下是 JSP 代码:

<%@ 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" %>  

<html>
<head>
    <title>SELECT operation</title>
</head>
<body>
<sql : setDataSource var="snapshot" driver="com.mysql.jdbc.Driver"
     url="jdbc:mysql://localhost/EMP"
     user="root" password="password"/>

<sql : query dataSource="${snapshot}" var="result">
 SELECT * from Employees;
</sql : query>

<table border="1" width="100%">
<tr>
<th>Emp ID</th>
<th>Age</th>
<th>First Name</th>
<th>Last Name</th>
</tr>
<c:forEach var="row" items="${result.rows}">
<tr>
<td><c:out value="${row.id}"/></td>
<td><c:out value="${row.age}"/></td>
<td><c:out value="${row.first}"/></td>
<td><c:out value="${row.last}"/></td>
</tr>
</c:forEach>
</table>
</body>
</html>  

但是我对下面的代码持怀疑态度(我从 JSP 程序代码中提取了代码),因为当我尝试关闭自定义标记的双冒号 (:) 前后的间隙时,我收到了一个运行时错误信息.

However I'm suspicious with the code below (I extracted the code form the JSP program code), as when i try to close the gaps before and after the double colons (:) of the custom tags I receive a run time error message.

<sql : setDataSource  
<sql : query dataSource  
</sql : query>   

下面是根文件夹和类路径:

JSP page: C:\Program Files\Apache Software Foundation\Tomcat 7.0\webapps\jsp pages\RegName.jsp  

CLASSPATH: C:\Program Files\Apache Software Foundation\Tomcat 7.0\lib\jsp-api.jar;C:\Program Files\Apache Software Foundation\Tomcat 7.0\lib\jstl-1.2.jar;C:\glassfish3\jdk\jre\lib;C:\Program Files (x86)\MySQL\MySQL Connector J\mysql-connector-java-5.1.27-bin.jar 

JAVA_HOME: C:\glassfish3\jdk  

Path:C:\Program Files\Apache Software Foundation\Tomcat 7.0\bin; C:\glassfish3\jdk\bin;C:\Program Files (x86)\MySQL\MySQL Server 5.0\bin 
Browser access of JSP: http://localhost:8080/jsp pages/FirstExample.jsp  

下面是命令行mysql信息:

Enter password: ********
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 6
Server version: 5.0.41-community-nt MySQL Community Edition (GPL)

Type 'help;' or '\h' for help. Type '\c' to clear the buffer.

mysql>

推荐答案

试试这个:

<tr>
<td>${row.id}</td>
<td>${row.age}</td>
<td>${row.first}</td>
<td>${row.last}</td>

这篇关于我收到一个空的 html/jsp 表,没有提取数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆