当我从 Netbeans 申请 运行 时,为什么我得到一个空白页?

Why do I get a blank page when running my application from Netbeans?

昨天一切正常,但今天每当我尝试从 IDE.[=18= 运行 我的应用程序时,我都会 运行 进入这个烦人的空白页面]

我的服务器是 Glassfish/port4848 然后 运行 来自 IDE http://localhost:8080/ecommerce/

问题似乎出在我在页面顶部添加这两个库引用时:

<!DOCTYPE html>
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@taglib prefix="sql" uri="http://java.sun.com/jsp/jstl/sql"%>
<%@page contentType="text/html" pageEncoding="UTF-8"%>

Sql 声明

<sql:query var="selectedCategory" dataSource="jdbc/ecommerce">
    SELECT name FROM category WHERE id = ?

<sql:param value="${pageContext.request.queryString}"/>
</sql:query>

<sql:query var="categoryProducts" dataSource="jdbc/ecommerce">
    SELECT * FROM product WHERE category_id = ?
    <sql:param value="${pageContext.request.queryString}"/>
</sql:query>

当我从顶部删除 SQL 语句时,当我在本地浏览器中请求该页面时,该页面加载得非常好。事情是我需要库能够 运行 这些 JSTL:

分类页/左栏(垂直菜单栏)

<c:forEach var="category" items="${categories.rows}">

        <c:choose>
            <c:when test="${category.id == pageContext.request.queryString}">
                <div class="categoryButton" id="selectedCategory">
                    <span class="categoryText">
                        ${category.name}
                    </span>
                </div>
            </c:when>
            <c:otherwise>
                <a href="category?${category.id}" class="categoryButton">
                    <div class="categoryText">
                        ${category.name}
                    </div>
                </a>
            </c:otherwise>
        </c:choose>
    </c:forEach>

在 table(右侧 column/products 容器)中展示产品

<c:forEach var="product" items="${categoryProducts.rows}" varStatus="iter">

    <tr class="${((iter.index % 2) == 0) ? 'lightBlue' : 'white'}">
        <td>
            <img src="${initParam.productImagePath}${product.name}.png"
                alt="${product.name}">
        </td>
        <td>
            ${product.name}
            <br>
            <span class="smallText">${product.description}</span>
        </td>
        <td>
            &euro; ${product.price} / unit
        </td>
        <td>
            <form action="addToCart" method="post">
                <input type="hidden"
                       name="productId"
                       value="${product.id}">
                <input type="submit"
                       value="add to cart">
            </form>
        </td>
    </tr>

</c:forEach>

我想明确地说,我的索引页没有问题,它还包含 JSTL 和顶部的两个引用。问题仅出在我的类别页面上。

完整类别源代码:

<!DOCTYPE html>
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@taglib prefix="sql" uri="http://java.sun.com/jsp/jstl/sql"%>

<%-- 
    Document   : category
    Created on : Feb 01, 2015, 7:56:19 PM
    Author     : PC
--%>


<sql:query var="categories" dataSource="jdbc/ecommerce">
    SELECT * FROM category
</sql:query>

        <sql:query var="selectedCategory" dataSource="jdbc/ecommerce">
    SELECT name FROM category WHERE id = ?
    <sql:param value="${pageContext.request.queryString}"/>
</sql:query>

    <sql:query var="categoryProducts" dataSource="jdbc/ecommerce">
    SELECT * FROM product WHERE category_id = ?
    <sql:param value="${pageContext.request.queryString}"/>
</sql:query>


<html>
  <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">

        <title>Ecommerce | Online Shopping</title>

        <script src="//code.jquery.com/jquery-1.11.2.min.js"></script>
        <script src="//code.jquery.com/jquery-migrate-1.2.1.min.js"></script>

        <link rel="stylesheet" type="text/css" href="css/category.css"/>
        <link rel="stylesheet" type="text/css" href="css/header.css"/>
        <link rel="stylesheet" type="text/css" href="css/footer.css"/>
    </head>

    <body style="margin: 0pt auto; padding: 0pt; max-width: 100%; width: 100%;">


        <div id="store_container">
<div id="store">
<div style="text-align: center;" id="category">
<div id="items">categories
</div>
<div class="cat_row">
<div style="text-align: left;"><span style="font-weight: bold;"><span style="background-color: rgb(239, 239, 239);">Brand new
products</span><br>
</span><span style="font-weight: normal;"></span><span style="font-weight: bold; background-color: rgb(239, 239, 239);">Items
on Sale</span><br>
<span style="text-decoration: underline;"></span></div>
</div>
<div class="cat_row">
<div style="text-align: left;"><span style="text-decoration: underline;">Shop
by technology</span><br>
<br>
<c:forEach var="category" items="${categories.rows}">

        <c:choose>
            <c:when test="${category.id == pageContext.request.queryString}">
                <div class="categoryButton" id="selectedCategory">
                    <span class="categoryText">
                        ${category.name}
                    </span>
                </div>
            </c:when>
            <c:otherwise>
                <a href="category?${category.id}" class="categoryButton">
                    <div class="categoryText">
                        ${category.name}
                    </div>
                </a>
            </c:otherwise>
        </c:choose>

    </c:forEach>
<br>
</div>
</div>
<div class="cat_row">
</div>
</div>
<div style="text-align: center;" id="thumbnails">
<div id="items"> Featured Items | ${selectedCategory.rows[0].name}
</div>
<br>
<div style="text-align: left;">
<div class="item_col">pages 1-2-3-4-5-6-7-8-10...<br>
</div>
<div style="text-align: left;" class="item_col2">24 per
page&nbsp;&nbsp; 48 per page&nbsp;&nbsp; 96 per page&nbsp;&nbsp; View
All<br>
</div>
</div>
<br>

<div id="thumb_container">
<table style="text-align: left; width: 100%;" border="0" cellpadding="0" cellspacing="0">

    <c:forEach var="product" items="${products}" varStatus="iter">
    <tbody>
    <tr>
      <td style="vertical-align: top; width: 275px;"><img src="${initParam.productImagePath}${product.name}.png"
                    alt="${product.name}"></td>
      <td style="vertical-align: top; width: 275px;"><img src="${initParam.productImagePath}${product.name}.png"
                    alt="${product.name}"></td>
      <td style="vertical-align: top; width: 275px;"><img src="${initParam.productImagePath}${product.name}.png"
                    alt="${product.name}"></td>
    </tr>
    <tr>
      <td style="vertical-align: top; width: 275px;">${product.name}<br>
      </td>
      <td style="vertical-align: top; width: 275px;">${product.name}<br>
      </td>
      <td style="vertical-align: top;">${product.name}<br>
      </td>
    </tr>
    <tr>
      <td style="vertical-align: top; width: 275px;">&cad; ${product.price} / unit<br>
      </td>
      <td style="vertical-align: top;">&cad; ${product.price} / unit<br>
      </td>
      <td style="vertical-align: top;">&cad; ${product.price} / unit<br>
      </td>
    </tr>
    <tr>
      <td style="vertical-align: top; width: 275px;">
      <table style="text-align: left; width: 100%;" border="0" cellpadding="0" cellspacing="0">
        <tbody>
          <tr>
            <td style="vertical-align: top; width: 50%;"><form action="addToWishlist" method="post">
                    <input type="hidden"
                           name="productId"
                           value="${product.id}">
                    <input type="submit"
                           value="Add To Wishlist">
                </form><br>
            </td>
            <td style="vertical-align: top;"><form action="addToCart" method="post">
                    <input type="hidden"
                           name="productId"
                           value="${product.id}">
                    <input type="submit"
                           value="Add To Cart">
                </form><br>
            </td>
          </tr>
        </tbody>
      </table>
      <br>
      </td>
      <td style="vertical-align: top;">
      <table style="text-align: left; width: 100%;" border="0" cellpadding="0" cellspacing="0">

          <tbody>
            <td style="vertical-align: top; width: 50%;"><form action="addToWishlist" method="post">
                    <input type="hidden"
                           name="productId"
                           value="${product.id}">
                    <input type="submit"
                           value="Add To Wishlist">
                </form><br>
            </td>
            <td style="vertical-align: top;"><form action="addToCart" method="post">
                    <input type="hidden"
                           name="productId"
                           value="${product.id}">
                    <input type="submit"
                           value="Add To Cart">
                </form></td>
          </tr>
        </tbody>
      </table>
      <br>
      </td>
      <td style="vertical-align: top;">
      <table style="text-align: left; width: 100%;" border="0" cellpadding="0" cellspacing="0">
        <tbody>
          <tr>
            <td style="vertical-align: top; width: 50%;"><form action="addToWishlist" method="post">
                    <input type="hidden"
                           name="productId"
                           value="${product.id}">
                    <input type="submit"
                           value="Add To Wishlist">
                </form><br>
            </td>
            <td style="vertical-align: top;"><form action="addToCart" method="post">
                    <input type="hidden"
                           name="productId"
                           value="${product.id}">
                    <input type="submit"
                           value="Add To Cart">
                </form></td>
          </tr>

        </tbody>
         </c:forEach>
      </table>
      <br>
      </td>
    </tr>
  </tbody>
</table>
<br>
<br>
</div>
</div>
</div>
</div>

    </body>
</html>

有什么想法吗?

非常感谢!

正确显示页面与taglib无关。

<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/sql" %>

多半是select说法不实的原因。

您的代码与变量不匹配!
因此 <c:forEachrowcount == 0 永远不会 运行 并且您的页面是空白的。

  • query var="selectedCategory" 从未使用过。
  • ${pageContext.request.queryString} 从未测试过。

测试 ${pageContext.request.queryString} 使用:look here


<sql:query var="selectedCategory" dataSource="jdbc/ecommerce">
    SELECT name FROM category WHERE id = ?

<sql:param value="${pageContext.request.queryString}"/>
</sql:query>
  • <c:forEach 使用 ${categories.rows} !它来自哪里?

 <c:forEach var="category" items="${categories.rows}">

用已知值替换param value="a valid ID"

<sql:query var="selectedCategory" dataSource="jdbc/ecommerce">
        SELECT name FROM category WHERE id = ?      
<sql:param value="a valid ID"/>
</sql:query>

<c:forEach var="category" items="${selectedCategory.rows}">
      <div class="categoryButton" id="selectedCategory">
           <span class="categoryText">
            ${category.name}
           </span>
      </div>
</c:forEach>

另外 items="${products}" 不匹配任何 sql 查询。

<c:forEach var="product" items="${products}" varStatus="iter">